Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) FuseSource, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 package org.fusesource.fabric.dosgi.tcp;

Hiram Chirino
 public class BlockingInvocationStrategy implements InvocationStrategy {
     public static final BlockingInvocationStrategy INSTANCE = new BlockingInvocationStrategy();
     private static final Callable<ObjectEMPTY_CALLABLE = new Callable<Object>() {
         public Object call() {
             return null;
     private class BlockingResponseFuture extends FutureTask<Objectimplements ResponseFutureAsyncCallback {
         private final ClassLoader loader;
         private final Method method;
         private final SerializationStrategy serializationStrategy;
         public BlockingResponseFuture(ClassLoader loaderMethod methodSerializationStrategy serializationStrategy) {
             this. = loader;
             this. = method;
             this. = serializationStrategy;
         public void set(DataByteArrayInputStream sourcethrows IOExceptionClassNotFoundException {
             try {
                 .decodeResponse(.getReturnType(), sourcethis);
             } catch (Throwable e) {
         public void fail(Throwable failure) {
         public void onSuccess(Object result) {
         public void onFailure(Throwable failure) {
     public ResponseFuture request(SerializationStrategy serializationStrategyClassLoader loaderMethod methodObject[] argsDataByteArrayOutputStream targetthrows Exception {
         assert Dispatch.getCurrentQueue() == null : "You should not do blocking RPC class when executing on a dispatch queue";
         serializationStrategy.encodeRequest(loadermethod.getParameterTypes(), argstarget);
         return new BlockingResponseFuture(loadermethodserializationStrategy);
     public void service(SerializationStrategy serializationStrategyClassLoader loaderMethod methodObject targetDataByteArrayInputStream requestStreamDataByteArrayOutputStream responseStreamRunnable onComplete) {
         int pos = responseStream.position();
         try {
             Object value = null;
             Throwable error = null;
             try {
                 Class<?>[] types = method.getParameterTypes();
                final Object[] args = new Object[types.length];
                value = method.invoke(targetargs);
            } catch (Throwable t) {
                if (t instanceof InvocationTargetException) {
                    error = t.getCause();
                } else {
                    error = t;
            serializationStrategy.encodeResponse(loadermethod.getReturnType(), valueerrorresponseStream);
        } catch(Exception e) {
            // we failed to encode the response.. reposition and write that error.
            try {
                serializationStrategy.encodeResponse(loadermethod.getReturnType(), nullnew RemoteException(e.toString()), responseStream);
            } catch (Exception unexpected) {
        } finally {
New to GrepCode? Check out our FAQ X