Example usage for java.rmi NoSuchObjectException getMessage

List of usage examples for java.rmi NoSuchObjectException getMessage

Introduction

In this page you can find the example usage for java.rmi NoSuchObjectException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message, including the message from the cause, if any, of this exception.

Usage

From source file:org.sybila.parasim.computation.lifecycle.impl.distributed.DistributedMemoryExecutorImpl.java

@Override
public <M extends Mergeable<M>> Future<M> submit(Computation<M> computation) {
    // init context
    Context context = getContext().context(ComputationScope.class);
    UUID computationId = UUID.randomUUID();

    // prepare status
    MutableStatus status = new SimpleStatus();
    RemoteMutableStatus remoteStatus = new RemoteMutableStatusWrapper(status);
    RemoteMutableStatus exportedRemoteStatus = null;
    Map<UUID, RemoteDescriptor> remoteDescriptors = new HashMap<>(remoteExecutors.size());

    try {// ww  w.  j a va  2 s . c om
        exportedRemoteStatus = (RemoteMutableStatus) UnicastRemoteObject.exportObject(remoteStatus);
        // start the computation on slave nodes
        for (RemoteExecutor executor : remoteExecutors) {
            executor.startComputation(computation.getClass(), exportedRemoteStatus, computationId);
            remoteDescriptors.put(executor.getId(), new RemoteDescriptor(executor.getHost(),
                    executor.getQueue(computationId), executor.getId()));
        }
        // prepare services
        ComputationFuture<M> future = new ComputationFuture<>(computationId, context, status);
        DistributedMemoryMucker mucker = new DistributedMemoryMucker(
                context.resolve(ComputationLifecycleConfiguration.class, Default.class), remoteDescriptors);
        // register progress listeners
        status.addProgressListerner(mucker);
        status.addProgressListerner(new RemoteComputationDestroyer(remoteStatus, computationId));
        status.addProgressListerner(future);
        // start the computation
        remoteExecutors.iterator().next().getQueue(computationId).emit(computation);
        // return future
        return future;
    } catch (RemoteException e) {
        try {
            if (exportedRemoteStatus != null) {
                UnicastRemoteObject.unexportObject(remoteStatus, true);
            }
        } catch (NoSuchObjectException ee) {
            LOGGER.error(ee.getMessage(), ee);
        } finally {
            for (RemoteExecutor executor : remoteExecutors) {
                try {
                    if (remoteDescriptors.containsKey(executor.getId())) {
                        executor.destroyComputation(computationId);
                    }
                } catch (RemoteException ee) {
                    LOGGER.error(ee.getMessage(), ee);
                }
            }
            try {
                context.destroy();
            } catch (Exception ee) {
                LOGGER.error("Can't destroy the computation context.");
            }
            throw new IllegalStateException("Can't submit the computation.", e);
        }
    }

}