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
     channelToClient.call(new Callable<Void,IOException>() {
         Void call() {
             ...
         }
         void checkRoles(RoleChecker checker) {
              checker.check(this,MyProtocol.CLIENT);
         }
     });
     
    Author:
    Kohsuke Kawaguchi
    See Also:
    RoleSensitive, RoleChecker
    • Field Detail

      • UNKNOWN

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

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

      • Role

        public Role​(String name)
      • Role

        public Role​(Class<?> name)
    • Method Detail

      • 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.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object