Package ch.ethz.iks.r_osgi.messages

Examples of ch.ethz.iks.r_osgi.messages.RemoteCallResultMessage


    invokeMsg.setMethodSignature(methodSignature);
    invokeMsg.setArgs(args);

    try {
      // send the message and get a MethodResultMessage in return
      final RemoteCallResultMessage resultMsg = (RemoteCallResultMessage) sendAndWait(invokeMsg);
      if (resultMsg.causedException()) {
        throw resultMsg.getException();
      }
      final Object result = resultMsg.getResult();
      if (result instanceof InputStreamHandle) {
        return getInputStreamProxy((InputStreamHandle) result);
      } else if (result instanceof OutputStreamHandle) {
        return getOutputStreamProxy((OutputStreamHandle) result);
      } else {
View Full Code Here


    final Integer xid = new Integer(RemoteOSGiServiceImpl.nextXid());

    synchronized (callbacks) {
      callbacks.put(xid, new AsyncCallback() {
        public void result(final RemoteOSGiMessage msg) {
          final RemoteCallResultMessage resultMsg = (RemoteCallResultMessage) msg;
          if (resultMsg.causedException()) {
            callback.remoteCallResult(false, resultMsg
                .getException());
          }
          final Object result = resultMsg.getResult();
          final Object res;
          if (result instanceof InputStreamHandle) {
            res = getInputStreamProxy((InputStreamHandle) result);
          } else if (result instanceof OutputStreamHandle) {
            res = getOutputStreamProxy((OutputStreamHandle) result);
View Full Code Here

        // invoke method
        try {
          Object result = method.invoke(serv.getServiceObject(),
              arguments);
          final RemoteCallResultMessage m = new RemoteCallResultMessage();
          m.setXID(invMsg.getXID());
          if (result instanceof InputStream) {
            m
                .setResult(getInputStreamPlaceholder((InputStream) result));
          } else if (result instanceof OutputStream) {
            m
                .setResult(getOutputStreamPlaceholder((OutputStream) result));
          } else {
            m.setResult(result);
          }
          return m;
        } catch (final InvocationTargetException t) {
          t.printStackTrace();
          throw t.getTargetException();
        }
      } catch (final Throwable t) {
        // TODO: send to log
        t.printStackTrace();
        final RemoteCallResultMessage m = new RemoteCallResultMessage();
        m.setXID(invMsg.getXID());
        m.setException(t);
        return m;
      }
    }
    case RemoteOSGiMessage.REMOTE_EVENT: {
      final RemoteEventMessage eventMsg = (RemoteEventMessage) msg;
      final Dictionary properties = eventMsg.getProperties();

      // transform the event timestamps
      final Long remoteTs;
      if ((remoteTs = (Long) properties.get(EventConstants.TIMESTAMP)) != null) {
        properties.put(EventConstants.TIMESTAMP, getOffset().transform(
            remoteTs));
      }

      final Event event = new Event(eventMsg.getTopic(), properties);

      // and deliver the event to the local framework
      if (RemoteOSGiServiceImpl.eventAdminTracker.getTrackingCount() > 0) {
        ((EventAdmin) RemoteOSGiServiceImpl.eventAdminTracker
            .getService()).postEvent(event);
      } else {
        // TODO: to log
        System.err.println("Could not deliver received event: " + event //$NON-NLS-1$
            + ". No EventAdmin available."); //$NON-NLS-1$
      }
      return null;
    }
    case RemoteOSGiMessage.TIME_OFFSET: {
      // add timestamp to the message and return the message to sender
      ((TimeOffsetMessage) msg).timestamp();
      return msg;
    }
    case RemoteOSGiMessage.STREAM_REQUEST: {
      final StreamRequestMessage reqMsg = (StreamRequestMessage) msg;
      try {
        // fetch stream object
        final Object stream = streams.get(new Integer(reqMsg
            .getStreamID()));
        if (stream == null) {
          throw new IllegalStateException(
              "Could not get stream with ID " //$NON-NLS-1$
                  + reqMsg.getStreamID());
        }
        // invoke operation on stream
        switch (reqMsg.getOp()) {
        case StreamRequestMessage.READ: {
          final int result = ((InputStream) stream).read();
          final StreamResultMessage m = new StreamResultMessage();
          m.setXID(reqMsg.getXID());
          m.setResult((short) result);
          return m;
        }
        case StreamRequestMessage.READ_ARRAY: {
          final byte[] b = new byte[reqMsg.getLenOrVal()];
          final int len = ((InputStream) stream).read(b, 0, reqMsg
              .getLenOrVal());
          final StreamResultMessage m = new StreamResultMessage();
          m.setXID(reqMsg.getXID());
          m.setResult(StreamResultMessage.RESULT_ARRAY);
          m.setLen(len);
          if (len > 0) {
            m.setData(b);
          }
          return m;
        }
        case StreamRequestMessage.WRITE: {
          ((OutputStream) stream).write(reqMsg.getLenOrVal());
          final StreamResultMessage m = new StreamResultMessage();
          m.setXID(reqMsg.getXID());
          m.setResult(StreamResultMessage.RESULT_WRITE_OK);
          return m;
        }
        case StreamRequestMessage.WRITE_ARRAY: {
          ((OutputStream) stream).write(reqMsg.getData());
          final StreamResultMessage m = new StreamResultMessage();
          m.setXID(reqMsg.getXID());
          m.setResult(StreamResultMessage.RESULT_WRITE_OK);
          return m;
        }
        default:
          throw new RemoteOSGiException(
              "Unimplemented op code for stream request " + msg); //$NON-NLS-1$
        }
      } catch (final IOException e) {
        final StreamResultMessage m = new StreamResultMessage();
        m.setXID(reqMsg.getXID());
        m.setResult(StreamResultMessage.RESULT_EXCEPTION);
        m.setException(e);
        return m;
      }
    }
    case RemoteOSGiMessage.REQUEST_BUNDLE:
      final RequestBundleMessage reqB = (RequestBundleMessage) msg;
View Full Code Here

TOP

Related Classes of ch.ethz.iks.r_osgi.messages.RemoteCallResultMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.