Example usage for java.lang.reflect Method toString

List of usage examples for java.lang.reflect Method toString

Introduction

In this page you can find the example usage for java.lang.reflect Method toString.

Prototype

public String toString() 

Source Link

Document

Returns a string describing this Method .

Usage

From source file:org.flite.cach3.aop.InvalidateSingleCacheAdvice.java

private void doInvalidate(final JoinPoint jp, final Object retVal) throws Throwable {
    if (isCacheDisabled()) {
        LOG.debug("Caching is disabled.");
        return;//from  w ww.j  ava 2s.  c o  m
    }

    final MemcachedClientIF cache = getMemcachedClient();
    final Method methodToCache = getMethodToCache(jp);
    List<InvalidateSingleCache> lAnnotations;

    if (methodToCache.getAnnotation(InvalidateSingleCache.class) != null) {
        lAnnotations = Arrays.asList(methodToCache.getAnnotation(InvalidateSingleCache.class));
    } else {
        lAnnotations = Arrays.asList(methodToCache.getAnnotation(InvalidateSingleCaches.class).value());
    }

    for (int i = 0; i < lAnnotations.size(); i++) {
        // This is injected caching.  If anything goes wrong in the caching, LOG the crap outta it,
        // but do not let it surface up past the AOP injection itself.
        try {
            final AnnotationInfo info = getAnnotationInfo(lAnnotations.get(i), methodToCache.getName());
            final String baseKey = getBaseKey(info.getAsString(AType.KEY_TEMPLATE),
                    info.getAsInteger(AType.KEY_INDEX, null), retVal, jp.getArgs(), methodToCache.toString(),
                    factory, methodStore);
            final String cacheKey = buildCacheKey(baseKey, info.getAsString(AType.NAMESPACE),
                    info.getAsString(AType.KEY_PREFIX));

            LOG.debug("Invalidating cache for key " + cacheKey);
            cache.delete(cacheKey);

            // Notify the observers that a cache interaction happened.
            final List<InvalidateSingleCacheListener> listeners = getPertinentListeners(
                    InvalidateSingleCacheListener.class, info.getAsString(AType.NAMESPACE));
            if (listeners != null && !listeners.isEmpty()) {
                for (final InvalidateSingleCacheListener listener : listeners) {
                    try {
                        listener.triggeredInvalidateSingleCache(info.getAsString(AType.NAMESPACE),
                                info.getAsString(AType.KEY_PREFIX, null), baseKey, retVal, jp.getArgs());
                    } catch (Exception ex) {
                        LOG.warn("Problem when triggering a listener.", ex);
                    }
                }
            }
        } catch (Throwable ex) {
            if (LOG.isDebugEnabled()) {
                LOG.warn("Caching on " + jp.toShortString() + " aborted due to an error.", ex);
            } else {
                LOG.warn("Caching on " + jp.toShortString() + " aborted due to an error: " + ex.getMessage());
            }
        }
    }
}

From source file:org.flite.cach3.aop.L2InvalidateMultiCacheAdvice.java

private void doInvalidate(final JoinPoint jp, final Object retVal) throws Throwable {
    if (isCacheDisabled()) {
        LOG.debug("Caching is disabled.");
        return;//from w w w . j a  v  a2s .  c o m
    }

    final Method methodToCache = getMethodToCache(jp);

    List<L2InvalidateMultiCache> lAnnotations;

    //        if (methodToCache.getAnnotation(InvalidateMultiCache.class) != null) {
    lAnnotations = Arrays.asList(methodToCache.getAnnotation(L2InvalidateMultiCache.class));
    //        } else {
    //            lAnnotations = Arrays.asList(methodToCache.getAnnotation(InvalidateMultiCaches.class).value());
    //        }

    for (int i = 0; i < lAnnotations.size(); i++) {
        // This is injected caching.  If anything goes wrong in the caching, LOG the crap outta it,
        // but do not let it surface up past the AOP injection itself.
        try {
            final AnnotationInfo info = getAnnotationInfo(lAnnotations.get(i), methodToCache.getName());
            final List<Object> keyObjects = (List<Object>) UpdateMultiCacheAdvice.getIndexObject(
                    info.getAsInteger(AType.KEY_INDEX), retVal, jp.getArgs(), methodToCache.toString());
            final List<String> baseKeys = UpdateMultiCacheAdvice.getBaseKeys(keyObjects,
                    info.getAsString(AType.KEY_TEMPLATE), retVal, jp.getArgs(), factory, methodStore);
            final List<String> fullKeys = new ArrayList<String>(baseKeys.size());
            for (final String base : baseKeys) {
                final String cacheKey = buildCacheKey(base, info.getAsString(AType.NAMESPACE),
                        info.getAsString(AType.KEY_PREFIX));
                fullKeys.add(cacheKey);
            }
            getCache().invalidateBulk(fullKeys);
        } catch (Throwable ex) {
            if (LOG.isDebugEnabled()) {
                LOG.warn("Caching on " + jp.toShortString() + " aborted due to an error.", ex);
            } else {
                LOG.warn("Caching on " + jp.toShortString() + " aborted due to an error: " + ex.getMessage());
            }
        }
    }
}

From source file:org.flite.cach3.aop.L2InvalidateSingleCacheAdvice.java

private void doInvalidate(final JoinPoint jp, final Object retVal) throws Throwable {
    if (isCacheDisabled()) {
        LOG.debug("Caching is disabled.");
        return;//from  w ww . ja  va  2  s. c  o m
    }

    final Method methodToCache = getMethodToCache(jp);
    List<L2InvalidateSingleCache> lAnnotations;

    //        if (methodToCache.getAnnotation(InvalidateSingleCache.class) != null) {
    lAnnotations = Arrays.asList(methodToCache.getAnnotation(L2InvalidateSingleCache.class));
    //        } else {
    //            lAnnotations = Arrays.asList(methodToCache.getAnnotation(InvalidateSingleCaches.class).value());
    //        }

    for (int i = 0; i < lAnnotations.size(); i++) {
        // This is injected caching.  If anything goes wrong in the caching, LOG the crap outta it,
        // but do not let it surface up past the AOP injection itself.
        try {
            final AnnotationInfo info = getAnnotationInfo(lAnnotations.get(i), methodToCache.getName());
            final String baseKey = CacheBase.getBaseKey(info.getAsString(AType.KEY_TEMPLATE),
                    info.getAsInteger(AType.KEY_INDEX, null), retVal, jp.getArgs(), methodToCache.toString(),
                    factory, methodStore);
            final String cacheKey = buildCacheKey(baseKey, info.getAsString(AType.NAMESPACE),
                    info.getAsString(AType.KEY_PREFIX));

            LOG.debug("Invalidating cache for key " + cacheKey);
            getCache().invalidateBulk(Arrays.asList(cacheKey));
        } catch (Throwable ex) {
            if (LOG.isDebugEnabled()) {
                LOG.warn("Caching on " + jp.toShortString() + " aborted due to an error.", ex);
            } else {
                LOG.warn("Caching on " + jp.toShortString() + " aborted due to an error: " + ex.getMessage());
            }
        }
    }
}

From source file:org.flite.cach3.aop.L2UpdateSingleCacheAdvice.java

private void doUpdate(final JoinPoint jp, final Object retVal) throws Throwable {
    if (isCacheDisabled()) {
        LOG.debug("Caching is disabled.");
        return;//from   w  w w.  j  a  v  a 2 s . c  o m
    }

    final Method methodToCache = getMethodToCache(jp);
    List<L2UpdateSingleCache> lAnnotations;

    //        if (methodToCache.getAnnotation(UpdateSingleCache.class) != null) {
    lAnnotations = Arrays.asList(methodToCache.getAnnotation(L2UpdateSingleCache.class));
    //        } else {
    //            lAnnotations = Arrays.asList(methodToCache.getAnnotation(UpdateSingleCaches.class).value());
    //        }

    for (int i = 0; i < lAnnotations.size(); i++) {
        // This is injected caching.  If anything goes wrong in the caching, LOG the crap outta it,
        // but do not let it surface up past the AOP injection itself.
        try {
            final AnnotationInfo info = getAnnotationInfo(lAnnotations.get(i), methodToCache.getName());
            final String baseKey = CacheBase.getBaseKey(info.getAsString(AType.KEY_TEMPLATE),
                    info.getAsInteger(AType.KEY_INDEX, null), retVal, jp.getArgs(), methodToCache.toString(),
                    factory, methodStore);
            final String cacheKey = buildCacheKey(baseKey, info.getAsString(AType.NAMESPACE),
                    info.getAsString(AType.KEY_PREFIX));
            final Object dataObject = CacheBase.getIndexObject(info.getAsInteger(AType.DATA_INDEX, null),
                    retVal, jp.getArgs(), methodToCache.toString());
            final Object submission = (dataObject == null) ? new PertinentNegativeNull() : dataObject;
            boolean cacheable = true;
            if (submission instanceof CacheConditionally) {
                cacheable = ((CacheConditionally) submission).isCacheable();
            }
            if (cacheable) {
                getCache().setBulk(ImmutableMap.of(cacheKey, submission),
                        info.<Duration>getAsType(AType.WINDOW, null));
            }
        } catch (Exception ex) {
            if (LOG.isDebugEnabled()) {
                LOG.warn("Caching on " + jp.toShortString() + " aborted due to an error.", ex);
            } else {
                LOG.warn("Caching on " + jp.toShortString() + " aborted due to an error: " + ex.getMessage());
            }
        }
    }
}

From source file:org.switchyard.component.resteasy.util.ClientInvoker.java

/**
 * Create a RESTEasy invoker client.//from  w  ww.  j a va 2s .  co  m
 *
 * @param basePath The base path for the class
 * @param resourceClass The JAX-RS Resource Class
 * @param method The JAX-RS Resource Class's method
 * @param model Configuration model
 */
public ClientInvoker(String basePath, Class<?> resourceClass, Method method, RESTEasyBindingModel model) {
    Set<String> httpMethods = IsHttpMethod.getHttpMethods(method);
    _baseUri = createUri(basePath);
    if ((httpMethods == null || httpMethods.size() == 0) && method.isAnnotationPresent(Path.class)
            && method.getReturnType().isInterface()) {
        _subResourcePath = createSubResourcePath(basePath, method);
    } else if (httpMethods == null || httpMethods.size() != 1) {
        throw RestEasyMessages.MESSAGES
                .youMustUseAtLeastOneButNoMoreThanOneHttpMethodAnnotationOn(method.toString());
    }
    _httpMethod = httpMethods.iterator().next();
    _resourceClass = resourceClass;
    _method = method;
    try {
        _uri = (UriBuilder) URIBUILDER_CLASS.newInstance();
    } catch (InstantiationException ie) {
        throw new RuntimeException(ie);
    } catch (IllegalAccessException iae) {
        throw new RuntimeException(iae);
    }
    _uri.uri(_baseUri);
    if (_resourceClass.isAnnotationPresent(Path.class)) {
        _uri.path(_resourceClass);
    }
    if (_method.isAnnotationPresent(Path.class)) {
        _uri.path(_method);
    }

    _providerFactory = new ResteasyProviderFactory();

    boolean useBuiltins = true; // use builtin @Provider classes by default
    if (model.getContextParamsConfig() != null) {
        Map<String, String> contextParams = model.getContextParamsConfig().toMap();

        // Set use builtin @Provider classes
        String registerBuiltins = contextParams.get(ResteasyContextParameters.RESTEASY_USE_BUILTIN_PROVIDERS);
        if (registerBuiltins != null) {
            useBuiltins = Boolean.parseBoolean(registerBuiltins);
        }

        // Register @Provider classes
        List<Class<?>> providerClasses = RESTEasyUtil.getProviderClasses(contextParams);
        if (providerClasses != null) {
            for (Class<?> pc : providerClasses) {
                _providerFactory.registerProvider(pc);
            }
        }

        List<ClientErrorInterceptor> interceptors = RESTEasyUtil.getClientErrorInterceptors(contextParams);
        if (interceptors != null) {
            for (ClientErrorInterceptor interceptor : interceptors) {
                _providerFactory.addClientErrorInterceptor(interceptor);
            }
        }
    }
    if (useBuiltins) {
        _providerFactory.setRegisterBuiltins(true);
        RegisterBuiltin.register(_providerFactory);
    }

    _extractorFactory = new DefaultEntityExtractorFactory();
    _extractor = _extractorFactory.createExtractor(_method);
    _marshallers = ClientMarshallerFactory.createMarshallers(_resourceClass, _method, _providerFactory, null);
    _accepts = MediaTypeHelper.getProduces(_resourceClass, method, null);
    ClientInvokerInterceptorFactory.applyDefaultInterceptors(this, _providerFactory, _resourceClass, _method);

    // Client executor
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    int port = _baseUri.getPort();
    if (_baseUri.getScheme().startsWith("https")) {
        if (port == -1) {
            port = 443;
        }
        SSLSocketFactory sslFactory = getSSLSocketFactory(model.getSSLContextConfig());
        if (sslFactory == null) {
            sslFactory = SSLSocketFactory.getSocketFactory();
        }
        schemeRegistry.register(new Scheme(_baseUri.getScheme(), port, sslFactory));
    } else {
        if (port == -1) {
            port = 80;
        }
        schemeRegistry.register(new Scheme(_baseUri.getScheme(), port, PlainSocketFactory.getSocketFactory()));
    }
    PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry);
    cm.setMaxTotal(200);
    cm.setDefaultMaxPerRoute(20);
    HttpClient httpClient = new DefaultHttpClient(cm);
    _executor = new ApacheHttpClient4Executor(httpClient);
    // register ApacheHttpClient4ExceptionMapper manually for local instance of ResteasyProviderFactory
    Type exceptionType = Types.getActualTypeArgumentsOfAnInterface(ApacheHttpClient4ExceptionMapper.class,
            ClientExceptionMapper.class)[0];
    _providerFactory.addClientExceptionMapper(new ApacheHttpClient4ExceptionMapper(), exceptionType);

    // Authentication settings
    if (model.hasAuthentication()) {
        // Set authentication
        AuthScope authScope = null;
        Credentials credentials = null;
        if (model.isBasicAuth()) {
            authScope = createAuthScope(model.getBasicAuthConfig().getHost(),
                    model.getBasicAuthConfig().getPort(), model.getBasicAuthConfig().getRealm());
            credentials = new UsernamePasswordCredentials(model.getBasicAuthConfig().getUser(),
                    model.getBasicAuthConfig().getPassword());
            // Create AuthCache instance
            AuthCache authCache = new BasicAuthCache();
            authCache.put(new HttpHost(authScope.getHost(), authScope.getPort()),
                    new BasicScheme(ChallengeState.TARGET));
            BasicHttpContext context = new BasicHttpContext();
            context.setAttribute(ClientContext.AUTH_CACHE, authCache);
            ((ApacheHttpClient4Executor) _executor).setHttpContext(context);
        } else {
            authScope = createAuthScope(model.getNtlmAuthConfig().getHost(),
                    model.getNtlmAuthConfig().getPort(), model.getNtlmAuthConfig().getRealm());
            credentials = new NTCredentials(model.getNtlmAuthConfig().getUser(),
                    model.getNtlmAuthConfig().getPassword(), "", model.getNtlmAuthConfig().getDomain());
        }
        ((DefaultHttpClient) httpClient).getCredentialsProvider().setCredentials(authScope, credentials);
    } else {
        ProxyModel proxy = model.getProxyConfig();
        if (proxy != null) {
            HttpHost proxyHost = null;
            if (proxy.getPort() != null) {
                proxyHost = new HttpHost(proxy.getHost(), Integer.valueOf(proxy.getPort()).intValue());
            } else {
                proxyHost = new HttpHost(proxy.getHost(), -1);
            }
            if (proxy.getUser() != null) {
                AuthScope authScope = new AuthScope(proxy.getHost(),
                        Integer.valueOf(proxy.getPort()).intValue(), AuthScope.ANY_REALM);
                Credentials credentials = new UsernamePasswordCredentials(proxy.getUser(), proxy.getPassword());
                AuthCache authCache = new BasicAuthCache();
                authCache.put(proxyHost, new BasicScheme(ChallengeState.PROXY));
                ((DefaultHttpClient) httpClient).getCredentialsProvider().setCredentials(authScope,
                        credentials);
                BasicHttpContext context = new BasicHttpContext();
                context.setAttribute(ClientContext.AUTH_CACHE, authCache);
                ((ApacheHttpClient4Executor) _executor).setHttpContext(context);
            }
            httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxyHost);
        }
    }
    Integer timeout = model.getTimeout();
    if (timeout != null) {
        HttpParams httpParams = httpClient.getParams();
        HttpConnectionParams.setConnectionTimeout(httpParams, timeout);
        HttpConnectionParams.setSoTimeout(httpParams, timeout);
    }
}

From source file:org.flite.cach3.aop.UpdateMultiCacheAdvice.java

private void doUpdate(final JoinPoint jp, final Object retVal) throws Throwable {
    if (isCacheDisabled()) {
        LOG.debug("Caching is disabled.");
        return;/*ww w.j a  v a2  s . c  o m*/
    }

    final MemcachedClientIF cache = getMemcachedClient();
    final Method methodToCache = getMethodToCache(jp);
    List<UpdateMultiCache> lAnnotations;

    if (methodToCache.getAnnotation(UpdateMultiCache.class) != null) {
        lAnnotations = Arrays.asList(methodToCache.getAnnotation(UpdateMultiCache.class));
    } else {
        lAnnotations = Arrays.asList(methodToCache.getAnnotation(UpdateMultiCaches.class).value());
    }

    for (int i = 0; i < lAnnotations.size(); i++) {
        try {
            // This is injected caching.  If anything goes wrong in the caching, LOG the crap outta it,
            // but do not let it surface up past the AOP injection itself.
            final AnnotationInfo info = getAnnotationInfo(lAnnotations.get(i), methodToCache.getName(),
                    getJitterDefault());
            List<Object> dataList = (List<Object>) getIndexObject(info.getAsInteger(AType.DATA_INDEX), retVal,
                    jp.getArgs(), methodToCache.toString());
            dataList = UpdateMultiCacheAdvice.getMergedDataList(dataList,
                    info.getAsString(AType.DATA_TEMPLATE, null), retVal, jp.getArgs(), factory);
            final List<Object> keyObjects = getKeyObjects(info.getAsInteger(AType.KEY_INDEX), retVal, jp,
                    methodToCache);
            final List<String> baseKeys = UpdateMultiCacheAdvice.getBaseKeys(keyObjects,
                    info.getAsString(AType.KEY_TEMPLATE, null), retVal, jp.getArgs(), factory, methodStore);
            final List<String> cacheKeys = new ArrayList<String>(baseKeys.size());
            for (final String base : baseKeys) {
                cacheKeys.add(buildCacheKey(base, info.getAsString(AType.NAMESPACE, null),
                        info.getAsString(AType.KEY_PREFIX, null)));
            }
            updateCache(cacheKeys, dataList, methodToCache, info.getAsInteger(AType.JITTER),
                    info.getAsInteger(AType.EXPIRATION), cache,
                    (Class) info.getAsType(AType.DATA_TEMPLATE_TYPE, String.class));

            // Notify the observers that a cache interaction happened.
            final List<UpdateMultiCacheListener> listeners = getPertinentListeners(
                    UpdateMultiCacheListener.class, info.getAsString(AType.NAMESPACE));
            if (listeners != null && !listeners.isEmpty()) {
                for (final UpdateMultiCacheListener listener : listeners) {
                    try {
                        listener.triggeredUpdateMultiCache(info.getAsString(AType.NAMESPACE),
                                info.getAsString(AType.KEY_PREFIX, null), baseKeys, dataList, retVal,
                                jp.getArgs());
                    } catch (Exception ex) {
                        LOG.warn("Problem when triggering a listener.", ex);
                    }
                }
            }
        } catch (Exception ex) {
            if (LOG.isDebugEnabled()) {
                LOG.warn("Caching on " + jp.toShortString() + " aborted due to an error.", ex);
            } else {
                LOG.warn("Caching on " + jp.toShortString() + " aborted due to an error: " + ex.getMessage());
            }
        }
    }
}

From source file:org.eclipse.wb.internal.core.eval.evaluators.InvocationEvaluator.java

private Object evaluate(EvaluationContext context, SuperMethodInvocation invocation) throws Exception {
    // prepare target
    Object thisValue = AstEvaluationEngine.evaluate(context, null);
    // prepare method
    Method method;
    {/*ww  w  . ja  v a  2  s .c  o  m*/
        IMethodBinding methodBinding = AstNodeUtils.getMethodBinding(invocation);
        Assert.isNotNull(methodBinding);
        method = getReflectionMethod(thisValue.getClass(), methodBinding);
    }
    // prepare argument values
    Object[] argumentValues = getArgumentValues(context, DomGenerics.arguments(invocation), true);
    // invoke method
    try {
        invocation.getRoot().setProperty(SUPER_MI_KEY, Boolean.TRUE);
        return method.invoke(thisValue, argumentValues);
    } catch (Throwable e) {
        throw new DesignerException(ICoreExceptionConstants.EVAL_SUPER_METHOD, e, context.getSource(invocation),
                method.toString(), getArguments_toString(argumentValues),
                AstEvaluationEngine.getUserStackTrace(e));
    }
}

From source file:org.flite.cach3.aop.L2UpdateMultiCacheAdvice.java

private void doUpdate(final JoinPoint jp, final Object retVal) throws Throwable {
    if (isCacheDisabled()) {
        LOG.debug("Caching is disabled.");
        return;//from  ww  w  . j  av  a2  s. c  o m
    }

    final Method methodToCache = getMethodToCache(jp);
    List<L2UpdateMultiCache> lAnnotations;

    //        if (methodToCache.getAnnotation(L2UpdateMultiCache.class) != null) {
    lAnnotations = Arrays.asList(methodToCache.getAnnotation(L2UpdateMultiCache.class));
    //        } else {
    //            lAnnotations = Arrays.asList();
    //            lAnnotations = Arrays.asList(methodToCache.getAnnotation(L2UpdateMultiCaches.class).value());
    //        }

    for (int i = 0; i < lAnnotations.size(); i++) {
        try {
            // This is injected caching.  If anything goes wrong in the caching, LOG the crap outta it,
            // but do not let it surface up past the AOP injection itself.
            final AnnotationInfo info = getAnnotationInfo(lAnnotations.get(i), methodToCache.getName());

            final List<Object> dataList = (List<Object>) UpdateMultiCacheAdvice.getIndexObject(
                    info.getAsInteger(AType.DATA_INDEX), retVal, jp.getArgs(), methodToCache.toString());
            final List<Object> keyObjects = UpdateMultiCacheAdvice
                    .getKeyObjects(info.getAsInteger(AType.KEY_INDEX), retVal, jp, methodToCache);
            final List<String> baseKeys = UpdateMultiCacheAdvice.getBaseKeys(keyObjects,
                    info.getAsString(AType.KEY_TEMPLATE, null), retVal, jp.getArgs(), factory, methodStore);
            final List<String> cacheKeys = new ArrayList<String>(baseKeys.size());
            for (final String base : baseKeys) {
                cacheKeys.add(buildCacheKey(base, info.getAsString(AType.NAMESPACE, null),
                        info.getAsString(AType.KEY_PREFIX, null)));
            }
            updateCache(cacheKeys, dataList, methodToCache, info.<Duration>getAsType(AType.WINDOW, null),
                    getCache());
        } catch (Exception ex) {
            if (LOG.isDebugEnabled()) {
                LOG.warn("Caching on " + jp.toShortString() + " aborted due to an error.", ex);
            } else {
                LOG.warn("Caching on " + jp.toShortString() + " aborted due to an error: " + ex.getMessage());
            }
        }
    }
}

From source file:org.flite.cach3.aop.UpdateSingleCacheAdvice.java

private void doUpdate(final JoinPoint jp, final Object retVal) throws Throwable {
    if (isCacheDisabled()) {
        LOG.debug("Caching is disabled.");
        return;//from   ww  w . j a v a 2s.  com
    }

    final MemcachedClientIF cache = getMemcachedClient();
    final Method methodToCache = getMethodToCache(jp);
    List<UpdateSingleCache> lAnnotations;

    if (methodToCache.getAnnotation(UpdateSingleCache.class) != null) {
        lAnnotations = Arrays.asList(methodToCache.getAnnotation(UpdateSingleCache.class));
    } else {
        lAnnotations = Arrays.asList(methodToCache.getAnnotation(UpdateSingleCaches.class).value());
    }

    for (int i = 0; i < lAnnotations.size(); i++) {
        // This is injected caching.  If anything goes wrong in the caching, LOG the crap outta it,
        // but do not let it surface up past the AOP injection itself.
        try {
            final AnnotationInfo info = getAnnotationInfo(lAnnotations.get(i), methodToCache.getName(),
                    getJitterDefault());
            final String baseKey = CacheBase.getBaseKey(info.getAsString(AType.KEY_TEMPLATE),
                    info.getAsInteger(AType.KEY_INDEX, null), retVal, jp.getArgs(), methodToCache.toString(),
                    factory, methodStore);
            final String cacheKey = buildCacheKey(baseKey, info.getAsString(AType.NAMESPACE),
                    info.getAsString(AType.KEY_PREFIX));
            Object dataObject = getIndexObject(info.getAsInteger(AType.DATA_INDEX, null), retVal, jp.getArgs(),
                    methodToCache.toString());
            dataObject = UpdateSingleCacheAdvice.getMergedData(dataObject,
                    info.getAsString(AType.DATA_TEMPLATE, null), retVal, jp.getArgs(), factory);
            final Class dataTemplateType = (Class) info.getAsType(AType.DATA_TEMPLATE_TYPE, String.class);
            final Object submission = (dataObject == null) ? new PertinentNegativeNull()
                    : applyDataTemplateType(dataObject, dataTemplateType);

            boolean cacheable = true;
            if (submission instanceof CacheConditionally) {
                cacheable = ((CacheConditionally) submission).isCacheable();
            }

            if (cacheable) {
                cache.set(cacheKey, calculateJitteredExpiration(info.getAsInteger(AType.EXPIRATION),
                        info.getAsInteger(AType.JITTER)), submission);
            }

            // Notify the observers that a cache interaction happened.
            final List<UpdateSingleCacheListener> listeners = getPertinentListeners(
                    UpdateSingleCacheListener.class, info.getAsString(AType.NAMESPACE));
            if (listeners != null && !listeners.isEmpty()) {
                for (final UpdateSingleCacheListener listener : listeners) {
                    try {
                        listener.triggeredUpdateSingleCache(info.getAsString(AType.NAMESPACE),
                                info.getAsString(AType.KEY_PREFIX, null), baseKey, dataObject, retVal,
                                jp.getArgs());
                    } catch (Exception ex) {
                        LOG.warn("Problem when triggering a listener.", ex);
                    }
                }
            }
        } catch (Exception ex) {
            if (LOG.isDebugEnabled()) {
                LOG.warn("Caching on " + jp.toShortString() + " aborted due to an error.", ex);
            } else {
                LOG.warn("Caching on " + jp.toShortString() + " aborted due to an error: " + ex.getMessage());
            }
        }
    }
}

From source file:it.unibo.alchemist.language.protelis.util.ProtelisLoader.java

private static MethodCall parseMethod(final JvmOperation jvmOp, final List<Expression> args,
        final Map<FasterString, FunctionDefinition> nameToFun,
        final Map<FunctionDef, FunctionDefinition> funToFun, final AtomicInteger id) {
    final boolean ztatic = jvmOp.isStatic();
    final List<AnnotatedTree<?>> arguments = parseArgs(args, nameToFun, funToFun, id);
    final String classname = jvmOp.getDeclaringType().getQualifiedName();
    try {//from  w w  w  .j a  v  a  2 s .co  m
        final Class<?> clazz = Class.forName(classname);
        /*
         * TODO: Check for return type and params: if param is Field and
         * return type is not then L.warn()
         */
        List<Method> tempList = new ArrayList<>();
        for (Method m : clazz.getMethods()) {
            if (ztatic) {
                if (Modifier.isStatic(m.getModifiers())) {
                    tempList.add(m);
                }
            }
        }
        /*
         * Same number of arguments
         */
        final int parameterCount = jvmOp.getParameters().size();
        List<Method> tempList2 = new ArrayList<>();
        for (Method m : tempList) {
            // TODO: Workaround for different Method API
            if (m.getParameterTypes().length == parameterCount) {
                tempList2.add(m);
            }
        }
        /*
         * Same name
         */
        final String methodName = jvmOp.getSimpleName();
        List<Method> res = new ArrayList<>();
        for (Method m : tempList2) {
            if (m.getName().equals(methodName)) {
                res.add(m);
            }
        }
        /*
         * There should be only one left - otherwise we have overloading,
         * and to properly deal with that we need type checking. The
         * following collection operation is for debug and warning purposes,
         * and should be removed as soon as we have a proper way to deal
         * with overloading in place. TODO
         */
        if (res.size() > 1) {
            final StringBuilder sb = new StringBuilder(64);
            sb.append("Method ");
            sb.append(jvmOp.getQualifiedName());
            sb.append('/');
            sb.append(parameterCount);
            sb.append(" is overloaded by:\n");
            for (Method m : res) {
                sb.append(m.toString());
                sb.append('\n'); // NOPMD
            }
            sb.append("Protelis can not (yet) properly deal with that.");
            L.warn(sb.toString());
        }
        if (res.isEmpty()) {
            throw new IllegalStateException("Can not bind any method that satisfies the name "
                    + jvmOp.getQualifiedName() + "/" + parameterCount + ".");
        }
        return new MethodCall(res.get(0), arguments, ztatic);
    } catch (ClassNotFoundException e) {
        throw new IllegalStateException("Class " + classname + " could not be found in classpath.");
    } catch (SecurityException e) {
        throw new IllegalStateException(
                "Class " + classname + " could not be loaded due to security permissions.");
    } catch (Error e) {
        throw new IllegalStateException("An error occured while loading class " + classname + ".");
    }

}