List of usage examples for java.lang Void TYPE
Class TYPE
To view the source code for java.lang Void TYPE.
Click Source Link
From source file:org.apache.camel.component.bean.BeanProcessor.java
public boolean process(Exchange exchange, AsyncCallback callback) { // do we have an explicit method name we always should invoke boolean isExplicitMethod = ObjectHelper.isNotEmpty(method); Object bean;/* w w w .j a va 2 s. com*/ BeanInfo beanInfo; try { bean = beanHolder.getBean(); beanInfo = beanHolder.getBeanInfo(); } catch (Throwable e) { exchange.setException(e); callback.done(true); return true; } // do we have a custom adapter for this POJO to a Processor // should not be invoked if an explicit method has been set Processor processor = getProcessor(); if (!isExplicitMethod && processor != null) { if (LOG.isTraceEnabled()) { LOG.trace("Using a custom adapter as bean invocation: " + processor); } try { processor.process(exchange); } catch (Throwable e) { exchange.setException(e); } callback.done(true); return true; } Message in = exchange.getIn(); // Now it gets a bit complicated as ProxyHelper can proxy beans which we later // intend to invoke (for example to proxy and invoke using spring remoting). // and therefore the message body contains a BeanInvocation object. // However this can causes problem if we in a Camel route invokes another bean, // so we must test whether BeanHolder and BeanInvocation is the same bean or not BeanInvocation beanInvoke = in.getBody(BeanInvocation.class); if (beanInvoke != null) { if (LOG.isTraceEnabled()) { LOG.trace("Exchange IN body is a BeanInvocation instance: " + beanInvoke); } Class<?> clazz = beanInvoke.getMethod().getDeclaringClass(); boolean sameBean = clazz.isInstance(bean); if (LOG.isTraceEnabled()) { LOG.debug("BeanHolder bean: " + bean.getClass() + " and beanInvocation bean: " + clazz + " is same instance: " + sameBean); } if (sameBean) { beanInvoke.invoke(bean, exchange); // propagate headers exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders()); callback.done(true); return true; } } // set temporary header which is a hint for the bean info that introspect the bean if (in.getHeader(Exchange.BEAN_MULTI_PARAMETER_ARRAY) == null) { in.setHeader(Exchange.BEAN_MULTI_PARAMETER_ARRAY, isMultiParameterArray()); } String prevMethod = null; MethodInvocation invocation; if (methodObject != null) { invocation = beanInfo.createInvocation(methodObject, bean, exchange); } else { // we just override the bean's invocation method name here if (isExplicitMethod) { prevMethod = in.getHeader(Exchange.BEAN_METHOD_NAME, String.class); in.setHeader(Exchange.BEAN_METHOD_NAME, method); } try { invocation = beanInfo.createInvocation(bean, exchange); } catch (Throwable e) { exchange.setException(e); callback.done(true); return true; } } if (invocation == null) { throw new IllegalStateException( "No method invocation could be created, no matching method could be found on: " + bean); } // remove temporary header in.removeHeader(Exchange.BEAN_MULTI_PARAMETER_ARRAY); Object value = null; try { AtomicBoolean sync = new AtomicBoolean(true); value = invocation.proceed(callback, sync); if (!sync.get()) { if (LOG.isTraceEnabled()) { LOG.trace("Processing exchangeId: " + exchange.getExchangeId() + " is continued being processed asynchronously"); } // the remainder of the routing will be completed async // so we break out now, then the callback will be invoked which then continue routing from where we left here return false; } if (LOG.isTraceEnabled()) { LOG.trace("Processing exchangeId: " + exchange.getExchangeId() + " is continued being processed synchronously"); } } catch (InvocationTargetException e) { // lets unwrap the exception when its an invocation target exception exchange.setException(e.getCause()); callback.done(true); return true; } catch (Throwable e) { exchange.setException(e); callback.done(true); return true; } finally { if (isExplicitMethod) { in.setHeader(Exchange.BEAN_METHOD_NAME, prevMethod); } } // if the method returns something then set the value returned on the Exchange if (!invocation.getMethod().getReturnType().equals(Void.TYPE) && value != Void.TYPE) { if (exchange.getPattern().isOutCapable()) { // force out creating if not already created (as its lazy) if (LOG.isDebugEnabled()) { LOG.debug("Setting bean invocation result on the OUT message: " + value); } exchange.getOut().setBody(value); // propagate headers exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders()); } else { // if not out then set it on the in if (LOG.isDebugEnabled()) { LOG.debug("Setting bean invocation result on the IN message: " + value); } exchange.getIn().setBody(value); } } callback.done(true); return true; }
From source file:org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory.java
private static boolean isGetter(Method method) { return ((method.getName().startsWith("get") && method.getReturnType() != Void.TYPE) || (method.getName().startsWith("is") && method.getReturnType().equals(boolean.class))) && method.getParameterTypes().length == 0 && !Modifier.isStatic(method.getModifiers()); }
From source file:com.kixeye.chassis.transport.websocket.WebSocketAction.java
/** * Scans the method and caches parameter info. *//* w w w. java 2 s .co m*/ private void scanMethod() { Class<?>[] parameters = method.getParameterTypes(); for (int p = 0; p < parameters.length; p++) { boolean allowCustomArgumentResolution = true; // check if we want a web-socket session if (WebSocketSession.class.equals(parameters[p])) { allowCustomArgumentResolution = false; if (parameterTypes.containsKey(ParameterType.WEB_SOCKET_SESSION)) { throw new RuntimeException( "Cannot have multiple parameters as web-socket sessions on method: " + method); } parameterTypes.put(ParameterType.WEB_SOCKET_SESSION, p); } else if (WebSocketEnvelope.class.equals(parameters[p])) { allowCustomArgumentResolution = false; if (parameterTypes.containsKey(ParameterType.ENVELOPE)) { throw new RuntimeException("Cannot have multiple parameters as envelope on method: " + method); } takesEnvelope = true; parameterTypes.put(ParameterType.ENVELOPE, p); } else { for (Annotation annotation : method.getParameterAnnotations()[p]) { if (annotation instanceof ActionPayload) { allowCustomArgumentResolution = false; if (parameterTypes.containsKey(ParameterType.ACTION_PAYLOAD)) { throw new RuntimeException( "Cannot have multiple parameters marked as payloads on method: " + method); } parameterTypes.put(ParameterType.ACTION_PAYLOAD, p); payloadClass = parameters[p]; payloadParameterIndex = p; for (Annotation secondaryAnnotation : method.getParameterAnnotations()[p]) { if (secondaryAnnotation instanceof Valid) { validatePayload = true; break; } } break; } else if (annotation instanceof ActionTransactionId) { allowCustomArgumentResolution = false; if (parameterTypes.containsKey(ParameterType.TRANSACTION_ID)) { throw new RuntimeException( "Cannot have multiple parameters marked as payloads on method: " + method); } parameterTypes.put(ParameterType.TRANSACTION_ID, p); break; } } } if (allowCustomArgumentResolution) { cacheCustomArgumentResolverForParameter(method, p); } } responseClass = method.getReturnType(); if (responseClass.equals(Void.TYPE)) { responseClass = null; } else if (responseClass.equals(DeferredResult.class)) { responseClass = (Class<?>) ((ParameterizedType) method.getGenericReturnType()) .getActualTypeArguments()[0]; } }
From source file:org.apache.hadoop.hbase.ipc.WritableRpcEngine.java
/** Expert: Make multiple, parallel calls to a set of servers. */ public Object[] call(Method method, Object[][] params, InetSocketAddress[] addrs, Class<? extends VersionedProtocol> protocol, User ticket, Configuration conf) throws IOException, InterruptedException { Invocation[] invocations = new Invocation[params.length]; for (int i = 0; i < params.length; i++) invocations[i] = new Invocation(method, protocol, params[i]); HBaseClient client = CLIENTS.getClient(conf); try {/*from ww w . j a v a2 s . c o m*/ Writable[] wrappedValues = client.call(invocations, addrs, protocol, ticket); if (method.getReturnType() == Void.TYPE) { return null; } Object[] values = (Object[]) Array.newInstance(method.getReturnType(), wrappedValues.length); for (int i = 0; i < values.length; i++) if (wrappedValues[i] != null) values[i] = ((HbaseObjectWritable) wrappedValues[i]).get(); return values; } finally { CLIENTS.stopClient(client); } }
From source file:org.apache.openejb.util.proxy.QueryProxy.java
private void remove(final Object[] args, final Class<?> returnType) { if (args != null && args.length == 1 && returnType.equals(Void.TYPE)) { Object entity = args[0];/*w w w. j ava2 s . c o m*/ if (!em.contains(entity)) { // reattach the entity if possible final Class<?> entityClass = entity.getClass(); final EntityType<? extends Object> et = em.getMetamodel().entity(entityClass); if (!et.hasSingleIdAttribute()) { throw new IllegalArgumentException("Dynamic EJB doesn't manage IdClass yet"); } SingularAttribute<?, ?> id = null; // = et.getId(entityClass); doesn't work with openJPA for (final SingularAttribute<?, ?> sa : et.getSingularAttributes()) { if (sa.isId()) { id = sa; break; } } if (id == null) { throw new IllegalArgumentException("id field not found"); } final String idName = id.getName(); final Object idValue; try { idValue = BeanUtils.getProperty(entity, idName); } catch (final InvocationTargetException e) { throw new IllegalArgumentException("can't invoke to get entity id"); } catch (final NoSuchMethodException e) { throw new IllegalArgumentException("can't find the method to get entity id"); } catch (final IllegalAccessException e) { throw new IllegalArgumentException("can't access field/method to get entity id"); } entity = em.getReference(et.getJavaType(), idValue); if (entity == null) { throw new IllegalArgumentException("entity " + entity + " is not managed and can't be found."); } } em.remove(entity); } else { throw new IllegalArgumentException(REMOVE_NAME + " should have only one parameter and return void"); } }
From source file:org.springframework.cloud.stream.reactive.StreamEmitterAnnotationBeanPostProcessor.java
@SuppressWarnings({ "rawtypes", "unchecked" }) private void invokeSetupMethodOnToTargetChannel(Method method, Object bean, String outboundName) { Object[] arguments = new Object[method.getParameterCount()]; Object targetBean = null;// w w w . j ava 2 s . c o m for (int parameterIndex = 0; parameterIndex < arguments.length; parameterIndex++) { MethodParameter methodParameter = new SynthesizingMethodParameter(method, parameterIndex); Class<?> parameterType = methodParameter.getParameterType(); Object targetReferenceValue = null; if (methodParameter.hasParameterAnnotation(Output.class)) { targetReferenceValue = AnnotationUtils .getValue(methodParameter.getParameterAnnotation(Output.class)); } else if (arguments.length == 1 && StringUtils.hasText(outboundName)) { targetReferenceValue = outboundName; } if (targetReferenceValue != null) { targetBean = this.applicationContext.getBean((String) targetReferenceValue); for (StreamListenerParameterAdapter<?, Object> streamListenerParameterAdapter : this.streamListenerParameterAdapters) { if (streamListenerParameterAdapter.supports(targetBean.getClass(), methodParameter)) { arguments[parameterIndex] = streamListenerParameterAdapter.adapt(targetBean, methodParameter); if (arguments[parameterIndex] instanceof FluxSender) { closeableFluxResources.add((FluxSender) arguments[parameterIndex]); } break; } } Assert.notNull(arguments[parameterIndex], "Cannot convert argument " + parameterIndex + " of " + method + "from " + targetBean.getClass() + " to " + parameterType); } else { throw new IllegalStateException(StreamEmitterErrorMessages.ATLEAST_ONE_OUTPUT); } } Object result; try { result = method.invoke(bean, arguments); } catch (Exception e) { throw new BeanInitializationException("Cannot setup StreamEmitter for " + method, e); } if (!Void.TYPE.equals(method.getReturnType())) { if (targetBean == null) { targetBean = this.applicationContext.getBean(outboundName); } boolean streamListenerResultAdapterFound = false; for (StreamListenerResultAdapter streamListenerResultAdapter : this.streamListenerResultAdapters) { if (streamListenerResultAdapter.supports(result.getClass(), targetBean.getClass())) { Closeable fluxDisposable = streamListenerResultAdapter.adapt(result, targetBean); closeableFluxResources.add(fluxDisposable); streamListenerResultAdapterFound = true; break; } } Assert.state(streamListenerResultAdapterFound, StreamEmitterErrorMessages.CANNOT_CONVERT_RETURN_TYPE_TO_ANY_AVAILABLE_RESULT_ADAPTERS); } }
From source file:com.tesobe.obp.transport.spi.MockResponder.java
public Response put(Decoder.Parameters ps, Map<String, ?> fields, Transport.Target t) { ps.type().map(type -> {// w w w . ja va2 s . co m assertThat(type, is("pain.001.001.03db")); return Void.TYPE; }).orElseGet(() -> { fail(); return Void.TYPE; }); assertThat(fields.get(Transaction.accountId), is("account-x")); assertThat(fields.get(Transaction.amount), is("10")); assertThat(fields.get(Transaction.bankId), is("bank-x")); assertThat(fields.get(Transaction.completedDate), is("1999-01-02T00:00:00.000Z")); assertThat(fields.get(Transaction.counterPartyId), is("counterPartyId-x")); assertThat(fields.get(Transaction.counterPartyName), is("counterPartyName-x")); assertThat(fields.get(Transaction.currency), is("currency-x")); assertThat(fields.get(Transaction.description), is("description-x")); assertThat(fields.get(Transaction.newBalanceAmount), is("123456.78")); assertThat(fields.get(Transaction.newBalanceCurrency), is("nbc-x")); assertThat(fields.get(Transaction.postedDate), is("1999-01-02T00:00:00.000Z")); assertThat(fields.get(Transaction.transactionId), is("transaction-x")); assertThat(fields.get(Transaction.type), is("type-x")); assertThat(fields.get(Transaction.userId), is("user-x")); return DefaultResponse.fromData(entity("transactionId", Objects.toString(fields.get("transactionId")))); }
From source file:org.springframework.cloud.stream.binder.kafka.streams.KafkaStreamsStreamListenerSetupMethodOrchestrator.java
@Override @SuppressWarnings({ "rawtypes", "unchecked" }) public void orchestrateStreamListenerSetupMethod(StreamListener streamListener, Method method, Object bean) { String[] methodAnnotatedOutboundNames = getOutboundBindingTargetNames(method); validateStreamListenerMethod(streamListener, method, methodAnnotatedOutboundNames); String methodAnnotatedInboundName = streamListener.value(); Object[] adaptedInboundArguments = adaptAndRetrieveInboundArguments(method, methodAnnotatedInboundName, this.applicationContext, this.streamListenerParameterAdapter); try {/* ww w . j av a 2 s . c om*/ ReflectionUtils.makeAccessible(method); if (Void.TYPE.equals(method.getReturnType())) { method.invoke(bean, adaptedInboundArguments); } else { Object result = method.invoke(bean, adaptedInboundArguments); if (result.getClass().isArray()) { Assert.isTrue(methodAnnotatedOutboundNames.length == ((Object[]) result).length, "Result does not match with the number of declared outbounds"); } else { Assert.isTrue(methodAnnotatedOutboundNames.length == 1, "Result does not match with the number of declared outbounds"); } if (result.getClass().isArray()) { Object[] outboundKStreams = (Object[]) result; int i = 0; for (Object outboundKStream : outboundKStreams) { Object targetBean = this.applicationContext.getBean(methodAnnotatedOutboundNames[i++]); for (StreamListenerResultAdapter streamListenerResultAdapter : this.streamListenerResultAdapters) { if (streamListenerResultAdapter.supports(outboundKStream.getClass(), targetBean.getClass())) { streamListenerResultAdapter.adapt(outboundKStream, targetBean); break; } } } } else { Object targetBean = this.applicationContext.getBean(methodAnnotatedOutboundNames[0]); for (StreamListenerResultAdapter streamListenerResultAdapter : this.streamListenerResultAdapters) { if (streamListenerResultAdapter.supports(result.getClass(), targetBean.getClass())) { streamListenerResultAdapter.adapt(result, targetBean); break; } } } } } catch (Exception ex) { throw new BeanInitializationException("Cannot setup StreamListener for " + method, ex); } }
From source file:org.dbg4j.core.adapters.impl.DefaultDebuggingAdapter.java
/** * Appends method invocation result to the debug data. Appends nothing if method returns <code>void</code>. Takes * {@link Adapter} annotation into account during result evaluation. * * @param data/* w w w. j a v a 2 s. c o m*/ * @param methodInvocationPoint * @param result * @see Debug * @see Adapter */ protected void appendResultInfo(@Nonnull DebugData data, @Nonnull MethodInvocationPoint methodInvocationPoint, @Nullable Object result) { Method method = methodInvocationPoint.getMethod(); if (method.getReturnType().equals(Void.TYPE)) { return; } String resultStr = UNKNOWN_VALUE; try { EvaluationAdapter evaluationAdapter = null; if (methodInvocationPoint.getMethod().isAnnotationPresent(Adapter.class)) { Adapter adapterAnnotation = methodInvocationPoint.getMethod().getAnnotation(Adapter.class); evaluationAdapter = adapterAnnotation.value().newInstance(); } if (evaluationAdapter == null) { evaluationAdapter = new DefaultEvaluationAdapter(); } resultStr = evaluationAdapter.evaluate(methodInvocationPoint.getMethod().getReturnType(), result); } catch (Exception ignored) { } data.set("Result", resultStr); }
From source file:com.nabla.project.application.tool.runner.ServiceInvoker.java
/** * DOCUMENT ME!// ww w . j a v a2s .c o m */ public void afterPropertiesSet() { if ((serviceInterface != null) && !serviceInterface.isInterface()) { throw new IllegalArgumentException("serviceInterface must be an interface"); } Method methods[] = serviceInterface.getDeclaredMethods(); for (Method method : methods) { if (isAsynchronousMethod(method) && !method.getReturnType().equals(Void.TYPE)) { throw new IllegalArgumentException( "serviceInterface for ServiceRunner must containt only method returning void : " + method); } } }