Class Role


public final class Role extends Object
Represents different roles two sides of the channel plays.

Often the communication on Channel is asymmetric (for example, one side acts like a server and the other side acts like a client), and therefore it is useful to be able to mark Callable with the intended parties that are supposed to run them. This in turn allows parties to verify that it is not running Callables that it is not supposed to be executing.

Roles are compared based on the instance equality, so typically they'd be instantiated as singletons. For example, if you are designing a client/server protocol, you would have two role instances like this:

 public class MyProtocol {
     public static final Role SERVER = new Role("server");
     public static final Role CLIENT = new Role("client");

Then the callables that are meant to be run on the client would check CLIENT from RoleSensitive.checkRoles(RoleChecker):

 // from the server Callable<Void,IOException>() {
     Void call() {
     void checkRoles(RoleChecker checker) {
Kohsuke Kawaguchi
See Also:
  • Field Details


      public static final Role UNKNOWN
      Used as a place holder when Callable didn't declare any role.

      public static final Collection<Role> UNKNOWN_SET
      Convenience singleton collection that only include UNKNOWN
  • Constructor Details

    • Role

      public Role(String name)
    • Role

      public Role(Class<?> name)
  • Method Details

    • getName

      public String getName()
      Gets a human readable name of this role. Names are not a formal part of the role equality. That is, two Role instances are considered different even if they have the same name.
    • toString

      public String toString()
      toString in class Object
    • equals

      public boolean equals(Object obj)
      equals in class Object
    • hashCode

      public int hashCode()
      hashCode in class Object