Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2013 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;
 
SerializedClient is a org.atmosphere.wasync.Client that guarantees ordered message delivery, in-line with the org.atmosphere.wasync.Socket.fire(java.lang.Object) invocation sequence.

A sequence of fire calls over a SerializedClient's socket (created through create() :

     socket.fire("message1").fire("message2");
 
guarantees that message1 arrives at the recipient-side before message2. By default, wAsync uses multiple underlying connections in delivering fire payloads. The SerializedClient guarantees that only one connection is used at any moment in time, while still providing an asynchronous fire interface to clients.

SerializedClient instances can be configured by means of a SerializedFireStage in deciding on the exact staging semantics and the (non-functional) quality properties of a supporting stage. The default implementation provided is DefaultSerializedFireStage.

Author(s):
Christian Bach
 
 
     @Override
     public Socket create(SerializedOptions options) {
         AsyncHttpClient asyncHttpClient = options.runtime();
         if (asyncHttpClient == null || asyncHttpClient.isClosed()) {
             asyncHttpClient = ClientUtil.createDefaultAsyncHttpClient(options);
             options.runtime(asyncHttpClient);
         }
         return new SerializedSocket(options);
     }

    
 
     @Override
     public Socket create() {
         AsyncHttpClient asyncHttpClient = ClientUtil.createDefaultAsyncHttpClient(newOptionsBuilder().reconnect(true).build());
 
         return new SerializedSocket(
                 new SerializedOptionsBuilder()
                         .runtime(asyncHttpClient)
                         .serializedFireStage(new DefaultSerializedFireStage())
                         .build());
     }

    
 
     @Override
         return new SerializedOptionsBuilder();
     }

    
 
     @Override
         SerializedRequestBuilder b = new SerializedRequestBuilder();
         return SerializedRequestBuilder.class.cast(b.resolver(.));
     }

    
 
     @Override
         AtmosphereRequestBuilder b;
         try {
             b = clazz.newInstance();
         } catch (InstantiationException e) {
             throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
    public static class SerializedRequestBuilder extends AtmosphereRequestBuilder {
        public SerializedRequestBuilder() {
            super();
            enableProtocol(true);
        }
    }
New to GrepCode? Check out our FAQ X