Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * 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
   * 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.
This annotation is used to decorate methods that are to be invoked in an asynchronous way.
Note that the piece of code inside such methods will be automatically protected so to avoid concurrency issues. Though, other parts of the code inside the same class will be not.
In order to prevent unexpected behaviors, it is advisable to avoid using the same class fields (unless immutable) in protected and non-protected code, or to call synchronous methods through routines as well.

The only use case in which this annotation is useful, is when an interface is used as a proxy of another class methods. The interface can take some input parameters in an asynchronous way. In such case, the value specified in the annotation will indicate the type of the parameter expected by the target method.

For example, a method taking two integers:


         public int sum(int i1, int i2);
can be proxied by a method defined as:


         public int sum(@Input(int.class) OutputChannel<Integer> i1, int i2);

Note that the transfer mode is automatically inferred by the proxy and the target types, unless specifically chosen through the annotation mode attribute.

Remember also that, in order for the annotation to properly work at run time, you will need to add the following rules to your Proguard file (if employing it for shrinking or obfuscation):


         -keepattributes RuntimeVisibleAnnotations

         -keepclassmembers class ** {

Created by davide-maestroni on 23/05/15.

 public @interface Input {

The input transfer mode.

the mode.
     InputMode mode() default .;

The parameter class.

the class.
     Class<?> value();

Input transfer mode type.
The mode indicates in which way a parameter is passed to the wrapped method.
     enum InputMode {

Value mode.
The variable is just read from an output channel.

The annotated parameters must extend an OutputChannel.

Collection mode.
The inputs are collected from the channel and passed as an array or collection to the wrapped method.

The annotated parameter must extend an OutputChannel and must be the only parameter accepted by the method.

Parallel mode.
Each input is passed to a different parallel invocation of the wrapped method.

The annotated parameter must be an array or implement an java.lang.Iterable and must be the only parameter accepted by the method.

Automatic mode.
The mode is automatically assigned based to the parameter or return type. Namely: if the parameters match the COLLECTION input mode, that one is chosen; if they match the VALUE input mode, it is chosen the latter; finally the PARALLEL input mode conditions are checked.
New to GrepCode? Check out our FAQ X