/** * Called by generated subclasses to enqueue a method invocation. */ public void addInvocation(AbstractRequest<?, ?> request) { state.invocations.add(request); for (Object arg : request.getRequestData().getOrderedParameters()) { retainArg(arg); } }
/** * Called by generated subclasses to enqueue a method invocation. */ public void addInvocation(AbstractRequest<?, ?> request) { /* * TODO(bobv): Support for multiple invocations per request needs to be ironed out. Once this * is done, addInvocation() can be removed from the DialectImpl interface and restored to to * AbstractRequestContext. */ if (!state.invocations.isEmpty()) { throw new RuntimeException("Only one invocation per request, pending backend support"); } state.invocations.add(request); for (Object arg : request.getRequestData().getOrderedParameters()) { retainArg(arg); } }
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (Object.class.equals(method.getDeclaringClass()) || Request.class.equals(method.getDeclaringClass())) { return method.invoke(req, args); } else if (BeanMethod.SET.matches(method) || BeanMethod.SET_BUILDER.matches(method)) { req.getRequestData().setNamedParameter(BeanMethod.SET.inferName(method), args[0]); return Void.TYPE.equals(method.getReturnType()) ? null : proxy; } throw new UnsupportedOperationException(method.toString()); } });
/** * This method comes from the {@link InstanceRequest} * interface. Instance methods place the instance in the first parameter slot. */ public Request<T> using(P instanceObject) { getRequestData().getOrderedParameters()[0] = instanceObject; /* * Instance methods enqueue themselves when their using() method is called. * This ensures that the instance parameter will have been set when * AbstractRequestContext.retainArg() is called. */ requestContext.addInvocation(this); return this; }
/** * Create an InvocationMessage for each remote method call being made by the context. */ private List<InvocationMessage> makePayloadInvocations() { MessageFactory f = MessageFactoryHolder.FACTORY; List<InvocationMessage> invocationMessages = new ArrayList<InvocationMessage>(); for (AbstractRequest<?, ?> invocation : state.invocations) { // RequestData is produced by the generated subclass RequestData data = invocation.getRequestData(); InvocationMessage message = f.invocation().as(); // Operation; essentially a method descriptor message.setOperation(data.getOperation()); // The arguments to the with() calls Set<String> refsToSend = data.getPropertyRefs(); if (!refsToSend.isEmpty()) { message.setPropertyRefs(refsToSend); } // Parameter values or references List<Splittable> parameters = new ArrayList<Splittable>(data.getOrderedParameters().length); for (Object param : data.getOrderedParameters()) { parameters.add(EntityCodex.encode(this, param)); } if (!parameters.isEmpty()) { message.setParameters(parameters); } invocationMessages.add(message); } return invocationMessages; }
public String makePayload() { RequestData data = state.invocations.get(0).getRequestData(); AutoBean<JsonRpcRequest> bean = MessageFactoryHolder.FACTORY.jsonRpcRequest(); JsonRpcRequest request = bean.as(); request.setVersion("2.0"); request.setApiVersion(data.getApiVersion()); request.setId(payloadId++); Map<String, Splittable> params = new HashMap<String, Splittable>(); for (Map.Entry<String, Object> entry : data.getNamedParameters().entrySet()) { Object obj = entry.getValue(); Splittable value = encode(obj); params.put(entry.getKey(), value); } if (data.getRequestResource() != null) { params.put("resource", encode(data.getRequestResource())); } request.setParams(params); request.setMethod(data.getOperation()); return AutoBeanCodex.encode(bean).getPayload(); }
public void processPayload(Receiver<Void> receiver, String payload) { Splittable raw = StringQuoter.split(payload); @SuppressWarnings("unchecked") Receiver<Object> callback = (Receiver<Object>) state.invocations.get(0).getReceiver(); if (!raw.isNull("error")) { Splittable error = raw.get("error"); ServerFailure failure = new ServerFailure(error.get("message").asString(), error.get("code").asString(), payload, true); fail(receiver, failure); return; } Splittable result = raw.get("result"); @SuppressWarnings("unchecked") Class<BaseProxy> target = (Class<BaseProxy>) state.invocations.get(0).getRequestData().getReturnType(); SimpleProxyId<BaseProxy> id = getRequestFactory().allocateId(target); AutoBean<BaseProxy> bean = createProxy(target, id, true); // XXX expose this as a proper API ((AbstractAutoBean<?>) bean).setData(result); // AutoBeanCodex.decodeInto(result, bean); if (callback != null) { callback.onSuccess(bean.as()); } if (receiver != null) { receiver.onSuccess(null); } }
/** * Called by generated subclasses to enqueue a method invocation. */ public void addInvocation(AbstractRequest<?, ?> request) { state.invocations.add(request); for (Object arg : request.getRequestData().getOrderedParameters()) { retainArg(arg); } }
/** * Called by generated subclasses to enqueue a method invocation. */ public void addInvocation(AbstractRequest<?, ?> request) { state.invocations.add(request); for (Object arg : request.getRequestData().getOrderedParameters()) { retainArg(arg); } }
/** * Called by generated subclasses to enqueue a method invocation. */ public void addInvocation(AbstractRequest<?, ?> request) { state.invocations.add(request); for (Object arg : request.getRequestData().getOrderedParameters()) { retainArg(arg); } }
/** * Called by generated subclasses to enqueue a method invocation. */ public void addInvocation(AbstractRequest<?, ?> request) { /* * TODO(bobv): Support for multiple invocations per request needs to be ironed out. Once this * is done, addInvocation() can be removed from the DialectImpl interface and restored to to * AbstractRequestContext. */ if (!state.invocations.isEmpty()) { throw new RuntimeException("Only one invocation per request, pending backend support"); } state.invocations.add(request); for (Object arg : request.getRequestData().getOrderedParameters()) { retainArg(arg); } }
/** * Called by generated subclasses to enqueue a method invocation. */ public void addInvocation(AbstractRequest<?, ?> request) { /* * TODO(bobv): Support for multiple invocations per request needs to be ironed out. Once this * is done, addInvocation() can be removed from the DialectImpl interface and restored to to * AbstractRequestContext. */ if (!state.invocations.isEmpty()) { throw new RuntimeException("Only one invocation per request, pending backend support"); } state.invocations.add(request); for (Object arg : request.getRequestData().getOrderedParameters()) { retainArg(arg); } }
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (Object.class.equals(method.getDeclaringClass()) || Request.class.equals(method.getDeclaringClass())) { return method.invoke(req, args); } else if (BeanMethod.SET.matches(method) || BeanMethod.SET_BUILDER.matches(method)) { req.getRequestData().setNamedParameter(BeanMethod.SET.inferName(method), args[0]); return Void.TYPE.equals(method.getReturnType()) ? null : proxy; } throw new UnsupportedOperationException(method.toString()); } });
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (Object.class.equals(method.getDeclaringClass()) || Request.class.equals(method.getDeclaringClass())) { return method.invoke(req, args); } else if (BeanMethod.SET.matches(method) || BeanMethod.SET_BUILDER.matches(method)) { req.getRequestData().setNamedParameter(BeanMethod.SET.inferName(method), args[0]); return Void.TYPE.equals(method.getReturnType()) ? null : proxy; } throw new UnsupportedOperationException(method.toString()); } });
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (Object.class.equals(method.getDeclaringClass()) || Request.class.equals(method.getDeclaringClass())) { return method.invoke(req, args); } else if (BeanMethod.SET.matches(method) || BeanMethod.SET_BUILDER.matches(method)) { req.getRequestData().setNamedParameter(BeanMethod.SET.inferName(method), args[0]); return Void.TYPE.equals(method.getReturnType()) ? null : proxy; } throw new UnsupportedOperationException(method.toString()); } });
/** * This method comes from the {@link InstanceRequest} * interface. Instance methods place the instance in the first parameter slot. */ public Request<T> using(P instanceObject) { getRequestData().getOrderedParameters()[0] = instanceObject; /* * Instance methods enqueue themselves when their using() method is called. * This ensures that the instance parameter will have been set when * AbstractRequestContext.retainArg() is called. */ requestContext.addInvocation(this); return this; }
/** * This method comes from the {@link InstanceRequest} * interface. Instance methods place the instance in the first parameter slot. */ public Request<T> using(P instanceObject) { getRequestData().getOrderedParameters()[0] = instanceObject; /* * Instance methods enqueue themselves when their using() method is called. * This ensures that the instance parameter will have been set when * AbstractRequestContext.retainArg() is called. */ requestContext.addInvocation(this); return this; }
/** * This method comes from the {@link InstanceRequest} * interface. Instance methods place the instance in the first parameter slot. */ public Request<T> using(P instanceObject) { getRequestData().getOrderedParameters()[0] = instanceObject; /* * Instance methods enqueue themselves when their using() method is called. * This ensures that the instance parameter will have been set when * AbstractRequestContext.retainArg() is called. */ requestContext.addInvocation(this); return this; }
public String makePayload() { RequestData data = state.invocations.get(0).getRequestData(); AutoBean<JsonRpcRequest> bean = MessageFactoryHolder.FACTORY.jsonRpcRequest(); JsonRpcRequest request = bean.as(); request.setVersion("2.0"); request.setApiVersion(data.getApiVersion()); request.setId(payloadId++); Map<String, Splittable> params = new HashMap<String, Splittable>(); for (Map.Entry<String, Object> entry : data.getNamedParameters().entrySet()) { Object obj = entry.getValue(); Splittable value = encode(obj); params.put(entry.getKey(), value); } if (data.getRequestResource() != null) { params.put("resource", encode(data.getRequestResource())); } request.setParams(params); request.setMethod(data.getOperation()); return AutoBeanCodex.encode(bean).getPayload(); }
public String makePayload() { RequestData data = state.invocations.get(0).getRequestData(); AutoBean<JsonRpcRequest> bean = MessageFactoryHolder.FACTORY.jsonRpcRequest(); JsonRpcRequest request = bean.as(); request.setVersion("2.0"); request.setApiVersion(data.getApiVersion()); request.setId(payloadId++); Map<String, Splittable> params = new HashMap<String, Splittable>(); for (Map.Entry<String, Object> entry : data.getNamedParameters().entrySet()) { Object obj = entry.getValue(); Splittable value = encode(obj); params.put(entry.getKey(), value); } if (data.getRequestResource() != null) { params.put("resource", encode(data.getRequestResource())); } request.setParams(params); request.setMethod(data.getOperation()); return AutoBeanCodex.encode(bean).getPayload(); }