Search in sources :

Example 26 with ECFException

use of org.eclipse.ecf.core.util.ECFException in project ecf by eclipse.

the class RemoteServiceImpl method callSync.

/**
 * call the service synchronously.
 *
 * @param call
 *            the call object.
 * @return the result or <code>null</code>
 * @see org.eclipse.ecf.remoteservice.IRemoteService#callSync(org.eclipse.ecf.remoteservice.IRemoteCall)
 */
public Object callSync(final IRemoteCall call) throws ECFException {
    Object[] ps = call.getParameters();
    final Object[] parameters = (ps == null) ? EMPTY_ARGS : ps;
    final Class[] formalParams = new Class[parameters.length];
    for (int i = 0; i < formalParams.length; i++) {
        formalParams[i] = call.getParameters()[i].getClass();
    }
    IFuture future = getSyncExecutor().execute(new IProgressRunnable() {

        public Object run(IProgressMonitor monitor) throws Exception {
            final Method method = ClassUtil.getMethod(service.getClass(), call.getMethod(), formalParams);
            return method.invoke(service, parameters);
        }
    }, null);
    Object result = null;
    try {
        result = future.get(call.getTimeout());
    } catch (OperationCanceledException e) {
        // $NON-NLS-1$
        throw new ECFException("callSync cancelled", e);
    } catch (InterruptedException e) {
        // $NON-NLS-1$
        throw new ECFException("callSync interrupted ", e);
    } catch (TimeoutException e) {
        // $NON-NLS-1$ //$NON-NLS-2$
        throw new ECFException("callSync timed out after " + Long.toString(call.getTimeout()) + "ms", new TimeoutException(call.getTimeout()));
    }
    IStatus status = future.getStatus();
    if (!status.isOK())
        // $NON-NLS-1$
        throw new ECFException("Exception during callSync", status.getException());
    return result;
}
Also used : Method(java.lang.reflect.Method) RemoteOSGiException(ch.ethz.iks.r_osgi.RemoteOSGiException) ECFException(org.eclipse.ecf.core.util.ECFException) ECFException(org.eclipse.ecf.core.util.ECFException)

Example 27 with ECFException

use of org.eclipse.ecf.core.util.ECFException in project ecf by eclipse.

the class MSNContainer method sendTypingMessage.

public void sendTypingMessage(ID toID, boolean isTyping, String body) throws ECFException {
    try {
        if (isTyping) {
            ChatSession cs = (ChatSession) chatSessions.get(toID);
            if (cs == null) {
                cs = client.createChatSession(toID.getName());
                cs.addChatSessionListener(new ChatSessionListener(toID));
                chatSessions.put(toID, cs);
            }
            cs.sendTypingNotification();
        }
    } catch (IOException e) {
        throw new ECFException(e);
    }
}
Also used : IChatSessionListener(org.eclipse.ecf.protocol.msn.events.IChatSessionListener) ECFException(org.eclipse.ecf.core.util.ECFException) IOException(java.io.IOException) ChatSession(org.eclipse.ecf.protocol.msn.ChatSession)

Example 28 with ECFException

use of org.eclipse.ecf.core.util.ECFException in project ecf by eclipse.

the class Client method connect.

public synchronized Object connect(ID remote, Object data, int timeout) throws ECFException {
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    debug("connect(" + remote + "," + data + "," + timeout + ")");
    if (socket != null)
        // $NON-NLS-1$
        throw new ECFException("Already connected");
    if (remote == null)
        // $NON-NLS-1$
        throw new ECFException("remote cannot be null");
    // parse remote ID to URI
    URI anURI = parseRemoteID(remote);
    // Create socket by calling createSocket
    final Socket s = createConnectSocket(anURI, timeout);
    ConnectResultMessage res = null;
    try {
        // Set socket options
        setSocketOptions(s);
        // Now we've got a connection so set our socket
        setSocket(s);
        outputStream = new ObjectOutputStream(s.getOutputStream());
        outputStream.flush();
        inputStream = ProviderPlugin.getDefault().createObjectInputStream(s.getInputStream());
        // $NON-NLS-1$
        debug("connect;" + anURI);
        // send connect data and get synchronous response
        send(new ConnectRequestMessage(anURI, (Serializable) data));
        res = (ConnectResultMessage) readObject();
    } catch (final IOException e) {
        // $NON-NLS-1$
        throw new ECFException("Exception during connection to " + remote.getName(), e);
    }
    // $NON-NLS-1$
    debug("connect;rcv:" + res);
    if (res == null)
        // $NON-NLS-1$
        throw new ECFException("Result cannot be null");
    // Setup threads
    setupThreads();
    // Return results.
    final Object ret = res.getData();
    // $NON-NLS-1$
    debug("connect;returning:" + ret);
    return ret;
}
Also used : ECFException(org.eclipse.ecf.core.util.ECFException)

Example 29 with ECFException

use of org.eclipse.ecf.core.util.ECFException in project ecf by eclipse.

the class AbstractActionDelegate method run.

public void run(IAction action) {
    if ((chatRoomContainer == null) || (selection == null)) {
        return;
    }
    try {
        Iterator iterator = selection.iterator();
        while (iterator.hasNext()) {
            IUser user = (IUser) iterator.next();
            String message = getMessage(getUsername(user));
            chatRoomContainer.getChatRoomMessageSender().sendMessage(message);
        }
    } catch (ECFException e) {
        StatusManager.getManager().handle(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ECFException(org.eclipse.ecf.core.util.ECFException) Iterator(java.util.Iterator) IUser(org.eclipse.ecf.core.user.IUser)

Example 30 with ECFException

use of org.eclipse.ecf.core.util.ECFException in project ecf by eclipse.

the class RpcRemoteServiceTest method testSyncCall.

public void testSyncCall() {
    IRemoteService rpcClientService = getRemoteServiceClientContainerAdapter(container).getRemoteService(registrationEcho.getReference());
    try {
        Object result = rpcClientService.callSync(getEchoCall());
        assertNotNull(result);
        assertTrue(ECHO_TEST_DATA.equals(result));
    } catch (ECFException e) {
        fail("Could not contact the service");
    }
}
Also used : ECFException(org.eclipse.ecf.core.util.ECFException) IRemoteService(org.eclipse.ecf.remoteservice.IRemoteService)

Aggregations

ECFException (org.eclipse.ecf.core.util.ECFException)42 IRemoteService (org.eclipse.ecf.remoteservice.IRemoteService)9 Iterator (java.util.Iterator)5 IStatus (org.eclipse.core.runtime.IStatus)5 ID (org.eclipse.ecf.core.identity.ID)5 Status (org.eclipse.core.runtime.Status)4 ContainerConnectException (org.eclipse.ecf.core.ContainerConnectException)4 IOException (java.io.IOException)3 IContainer (org.eclipse.ecf.core.IContainer)3 Action (org.eclipse.jface.action.Action)3 IAction (org.eclipse.jface.action.IAction)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 List (java.util.List)2 TimeoutException (java.util.concurrent.TimeoutException)2 Namespace (org.eclipse.ecf.core.identity.Namespace)2 IConnectContext (org.eclipse.ecf.core.security.IConnectContext)2 IUser (org.eclipse.ecf.core.user.IUser)2 IChatRoomInfo (org.eclipse.ecf.presence.chatroom.IChatRoomInfo)2 IEcho (org.eclipse.ecf.tests.remoteservice.rpc.common.IEcho)2