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;

A function is asynchronously invoked when a response is received, complete or not.

This library supports predefined life cycle's events (@link Event} that can be used. For example, a Function can be defined for handling IOException:

 

class Function<IOException>() { public void on(IOEXception ex) { } }

This function can be registered using the Socket.on(org.atmosphere.wasync.Function) as
 

socket.on(new Function<IOEXception>() { .... }

This is the equivalent of doing
 

socket.on(Event.ERROR, new Function<IOEXception>() { .... }

Anonymous functions call also be invoked if a Decoder match its type
 

socket.decoder(new Decoder<String, POJO>(){ @Override public POJO decode(Event e, String message) { return new POJO(message); } }

.on(new Function<POJO>() { .... }

Parameters:
<T>
Author(s):
Jeanfrancois Arcand
public interface Function<T> {

    
A function that will be invoked when a object of type T is defined.

Parameters:
t A function that will be invoked when a object of type T is defined.
    void on(T t);
New to GrepCode? Check out our FAQ X