Search in sources :

Example 1 with IgfsIpcCommand

use of org.apache.ignite.internal.igfs.common.IgfsIpcCommand in project ignite by apache.

the class IgfsIpcHandler method handleAsync.

/**
 * {@inheritDoc}
 */
@Override
public IgniteInternalFuture<IgfsMessage> handleAsync(final IgfsClientSession ses, final IgfsMessage msg, final DataInput in) {
    try {
        // Even if will be closed right after this call, response write error will be ignored.
        if (stopping)
            return null;
        final IgfsIpcCommand cmd = msg.command();
        IgniteInternalFuture<IgfsMessage> fut;
        switch(cmd) {
            // Execute not-blocking command synchronously in worker thread.
            case WRITE_BLOCK:
            case MAKE_DIRECTORIES:
            case LIST_FILES:
            case LIST_PATHS:
                {
                    fut = executeSynchronously(ses, cmd, msg, in);
                    break;
                }
            // Execute command asynchronously in pool.
            default:
                {
                    try {
                        final GridFutureAdapter<IgfsMessage> fut0 = new GridFutureAdapter<>();
                        pool.execute(new Runnable() {

                            @Override
                            public void run() {
                                try {
                                    fut0.onDone(execute(ses, cmd, msg, in));
                                } catch (Exception e) {
                                    fut0.onDone(e);
                                }
                            }
                        });
                        fut = fut0;
                    } catch (RejectedExecutionException ignored) {
                        fut = executeSynchronously(ses, cmd, msg, in);
                    }
                }
        }
        // Pack result object into response format.
        return fut;
    } catch (Exception e) {
        return new GridFinishedFuture<>(e);
    }
}
Also used : IgfsIpcCommand(org.apache.ignite.internal.igfs.common.IgfsIpcCommand) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgfsMessage(org.apache.ignite.internal.igfs.common.IgfsMessage) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IgfsOutOfSpaceException(org.apache.ignite.igfs.IgfsOutOfSpaceException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Aggregations

IOException (java.io.IOException)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 IgfsOutOfSpaceException (org.apache.ignite.igfs.IgfsOutOfSpaceException)1 IgfsIpcCommand (org.apache.ignite.internal.igfs.common.IgfsIpcCommand)1 IgfsMessage (org.apache.ignite.internal.igfs.common.IgfsMessage)1 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)1