org.atmosphere.wasync
Interface FunctionResolver


public interface FunctionResolver

FunctionResolver are useful for mapping received message with a Function.

     Client client = ClientFactory.getDefault().newClient();

     RequestBuilder request = client.newRequestBuilder()
             .method(Request.METHOD.GET)
             .uri(targetUrl + "/suspend")
             .decoder(new Decoder<String, POJO>() {
                 @Override
                 public POJO decode(String s) {
                     return new POJO(s);
                 }
             })
             .transport(Request.TRANSPORT.WEBSOCKET);

     Socket socket = client.create();
     socket.on(Event.MESSAGE, new Function<POJO>() {
         @Override
         public void on(POJO t) {
             response.set(t);
         }
     })
 
or when a Decoder share the same type as the defined Function. For example:
     Client client = ClientFactory.getDefault().newClient();

     RequestBuilder request = client.newRequestBuilder()
             .method(Request.METHOD.GET)
             .uri(targetUrl + "/suspend")
             .decoder(new Decoder<String, POJO>() {
                 @Override
                 public POJO decode(String s) {
                     return new POJO(s);
                 }
             })
             .transport(Request.TRANSPORT.WEBSOCKET);

     Socket socket = client.create();
     socket.on(new Function<POJO>() {
         @Override
         public void on(POJO t) {
             response.set(t);
         }
     })
 
An application can define its own Decoder to Function Mapper be writing the appropriate FunctionResolver. By default, the DEFAULT is used.

Author:
Jeanfrancois Arcand

Field Summary
static FunctionResolver DEFAULT
           
 
Method Summary
 boolean resolve(String message, Object functionName, FunctionWrapper fn)
          Resolve the current message
 

Field Detail

DEFAULT

static final FunctionResolver DEFAULT
Method Detail

resolve

boolean resolve(String message,
                Object functionName,
                FunctionWrapper fn)
Resolve the current message

Parameters:
message - the original response's body received
functionName - the default function name taken from Event or from a custom FunctionResolver
fn - The current FunctionWrapper
Returns:
true if the Function can be invoked.


Copyright © 2013. All Rights Reserved.