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;
}
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);
}
}
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;
}
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));
}
}
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");
}
}
Aggregations