public final class Role extends Object
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);
}
});
RoleSensitive,
RoleChecker| Modifier and Type | Field and Description |
|---|---|
static Role |
UNKNOWN
Used as a place holder when
Callable didn't declare any role. |
static Collection<Role> |
UNKNOWN_SET
Convenience singleton collection that only include
UNKNOWN |
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object obj) |
String |
getName()
Gets a human readable name of this role.
|
int |
hashCode() |
String |
toString() |
public static final Role UNKNOWN
Callable didn't declare any role.public static final Collection<Role> UNKNOWN_SET
UNKNOWNCopyright © 2004–2020. All rights reserved.