org.atmosphere.wasync
Interface FunctionResolver

All Known Implementing Classes:
DefaultFunctionResolver

public interface FunctionResolver

FunctionResolver are useful for mapping received message with a Function. By default, only the predefined function Function.MESSAGE are automatically mapped to 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(Function.MESSAGE.message.name(), 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 Function.MESSAGE be writing the appropriate FunctionResolver. By default, the DefaultFunctionResolver is used.

Author:
Jeanfrancois Arcand

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

Method Detail

resolve

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

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


Copyright © 2013. All Rights Reserved.