Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012 Jeanfrancois Arcand
   *
   * Licensed under the Apache License, Version 2.0 (the "License"); you may not
   * use this file except in compliance with the License. You may obtain a copy of
   * the License at
   *
   * http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  * License for the specific language governing permissions and limitations under
  * the License.
  */
 package org.atmosphere.wasync.serial;
 
 
 import java.io.Reader;
 import java.util.List;
Serial extension for the org.atmosphere.wasync.impl.SocketRuntime

Author(s):
Jeanfrancois Arcand
 
 public class SerialSocketRuntime extends SocketRuntime {
 
     private final static Logger logger = LoggerFactory.getLogger(SerialSocketRuntime.class);
     private final SerializedSocket serializedSocket;
 
     public SerialSocketRuntime(Transport transportOptions optionsDefaultFuture rootFutureSerializedSocket serializedSocket,  List<FunctionWrapperfunctions) {
         super(transportoptionsrootFuturefunctions);
         this. = serializedSocket;
     }
 
     @Override
     public Future write(Request requestObject datathrows IOException {
 
         if (WebSocketTransport.class.isAssignableFrom(.getClass())) {
             Object object = invokeEncoder(request.encoders(), data);
             webSocketWrite(requestobjectdata);
         } else {
             // Execute encoder
             Object encodedPayload = invokeEncoder(request.encoders(), data);
             if (!(InputStream.class.isAssignableFrom(encodedPayload.getClass())
                             || Reader.class.isAssignableFrom(encodedPayload.getClass())
                             || String.class.isAssignableFrom(encodedPayload.getClass())
                             || byte[].class.isAssignableFrom(encodedPayload.getClass())
                     )) {
                 throw new IllegalStateException("No Encoder for " + data);
             }
 
             if (.getSerializedFireStage() != null) {
                 final SettableFuture<Responsefuture = SettableFuture.create();
                 .getSerializedFireStage().enqueue(encodedPayloadfuture);
                 return new Future() {
 
                     @Override
                     public Future fire(Object datathrows IOException {
                         return .fire(data);
                     }
 
                     @Override
                     public Future done() {
                         ListenableFuture.class.cast(future).done();
                         return this;
                     }
 
                     @Override
                     public boolean cancel(boolean mayInterruptIfRunning) {
                         return future.cancel(mayInterruptIfRunning);
                     }
 
                     @Override
                     public boolean isCancelled() {
                         return future.isCancelled();
                     }
 
                    @Override
                    public boolean isDone() {
                        return future.isDone();
                    }
                    @Override
                    public Socket get() throws InterruptedExceptionExecutionException {
                        future.get();
                        return ;
                    }
                    @Override
                    public Socket get(long timeoutTimeUnit unitthrows InterruptedExceptionExecutionExceptionTimeoutException {
                        future.get(timeoutunit);
                        return ;
                    }
                };
            } else {
                final ListenableFuture<Responsefuture = .directWrite(encodedPayload);
                return new Future() {
                    @Override
                    public Future fire(Object datathrows IOException {
                        return .fire(data);
                    }
                    @Override
                    public Future done() {
                        future.done();
                        return this;
                    }
                    @Override
                    public boolean cancel(boolean mayInterruptIfRunning) {
                        return future.cancel(mayInterruptIfRunning);
                    }
                    @Override
                    public boolean isCancelled() {
                        return future.isCancelled();
                    }
                    @Override
                    public boolean isDone() {
                        return future.isDone();
                    }
                    @Override
                    public Socket get() throws InterruptedExceptionExecutionException {
                        future.get();
                        return ;
                    }
                    @Override
                    public Socket get(long timeoutTimeUnit unitthrows InterruptedExceptionExecutionExceptionTimeoutException {
                        future.get(timeoutunit);
                        return ;
                    }
                };
            }
        }
        return ;
    }
New to GrepCode? Check out our FAQ X