org.avis.security
Class Keys

java.lang.Object
  extended by org.avis.security.Keys

public class Keys
extends Object

A key collection used to secure notifications. A key collection contains zero or more mappings from a key scheme to the keys registered for that scheme.

Once in use, key collections should be treated as immutable i.e. never be modified directly after construction.

See also section 7.4 of the client protocol spec.

Author:
Matthew Phillips

Nested Class Summary
static class Keys.Delta
          Represents a delta (diff) between two key sets.
 
Field Summary
static Keys EMPTY_KEYS
          An empty, immutable key collection.
 
Constructor Summary
Keys()
           
Keys(Keys keys)
           
 
Method Summary
 void add(DualKeyScheme scheme, DualKeyScheme.Subset subset, Key key)
          Add a key for dual key scheme.
 void add(Keys keys)
          Add all keys in a collection.
 void add(SingleKeyScheme scheme, Key key)
          Add a key for single key scheme.
 Keys addedTo(Keys keys)
          Shortcut to efficiently generate a key collection that represents this key collection's union with another.
static Keys decode(org.apache.mina.common.ByteBuffer in)
           
 Keys delta(Keys toAdd, Keys toRemove)
          Create a new key collection with some keys added/removed.
 Keys.Delta deltaFrom(Keys keys)
          Compute the changes between one key collection and another.
 void encode(org.apache.mina.common.ByteBuffer out)
           
 boolean equals(Keys keys)
           
 boolean equals(Object object)
           
 int hashCode()
           
 boolean isEmpty()
          True if no keys are in the collection.
 boolean match(Keys producerKeys)
          Test whether a given key collection matches this one for the purpose of notification delivery.
 void remove(DualKeyScheme scheme, DualKeyScheme.Subset subset, Key key)
          Remove a key for dual key scheme.
 void remove(Keys keys)
          Remove all keys in a collection.
 void remove(SingleKeyScheme scheme, Key key)
          Remove a key for single key scheme.
 int size()
          Return the total number of keys in this key collection.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_KEYS

public static final Keys EMPTY_KEYS
An empty, immutable key collection.

Constructor Detail

Keys

public Keys()

Keys

public Keys(Keys keys)
Method Detail

isEmpty

public boolean isEmpty()
True if no keys are in the collection.


size

public int size()
Return the total number of keys in this key collection.


addedTo

public Keys addedTo(Keys keys)
Shortcut to efficiently generate a key collection that represents this key collection's union with another.

Parameters:
keys - The keys to add.
Returns:
If keys is empty, this method will simply return this collection. If this collection is empty, keys will be returned. Otherwise a new collection instance is created as the union of both.

add

public void add(SingleKeyScheme scheme,
                Key key)
Add a key for single key scheme.

Parameters:
scheme - The key scheme.
key - The key to add.
See Also:
remove(SingleKeyScheme, Key)

remove

public void remove(SingleKeyScheme scheme,
                   Key key)
            throws IllegalArgumentException
Remove a key for single key scheme.

Parameters:
scheme - The key scheme.
key - The key to remove.
Throws:
IllegalArgumentException
See Also:
add(SingleKeyScheme, Key)

add

public void add(DualKeyScheme scheme,
                DualKeyScheme.Subset subset,
                Key key)
         throws IllegalArgumentException
Add a key for dual key scheme.

Parameters:
scheme - The key scheme.
subset - The key subset (PRODUCER or CONSUMER) to add the key to.
key - The key to add.
Throws:
IllegalArgumentException
See Also:
remove(DualKeyScheme, org.avis.security.DualKeyScheme.Subset, Key)

remove

public void remove(DualKeyScheme scheme,
                   DualKeyScheme.Subset subset,
                   Key key)
Remove a key for dual key scheme.

Parameters:
scheme - The key scheme.
subset - The key subset (PRODUCER or CONSUMER) to remove the key from.
key - The key to remove.
See Also:
add(DualKeyScheme, org.avis.security.DualKeyScheme.Subset, Key)

add

public void add(Keys keys)
Add all keys in a collection.

Parameters:
keys - The keys to add.
See Also:
remove(Keys)

remove

public void remove(Keys keys)
Remove all keys in a collection.

Parameters:
keys - The keys to remove.
See Also:
add(Keys)

delta

public Keys delta(Keys toAdd,
                  Keys toRemove)
Create a new key collection with some keys added/removed. This does not modify the current collection.

Parameters:
toAdd - Keys to add.
toRemove - Keys to remove
Returns:
A new key set with keys added/removed. If both add/remove key sets are empty, this returns the current instance.
See Also:
deltaFrom(Keys)

deltaFrom

public Keys.Delta deltaFrom(Keys keys)
Compute the changes between one key collection and another.

Parameters:
keys - The target key collection.
Returns:
The delta (i.e. key sets to be added and removed) required to change this collection into the target.
See Also:
delta(Keys, Keys)

match

public boolean match(Keys producerKeys)
Test whether a given key collection matches this one for the purpose of notification delivery.

Parameters:
producerKeys - The producer keys to match against this (consumer) key collection.
Returns:
True if a consumer using this key collection could receive a notification from a producer with the given producer key collection.

encode

public void encode(org.apache.mina.common.ByteBuffer out)

decode

public static Keys decode(org.apache.mina.common.ByteBuffer in)
                   throws org.apache.mina.filter.codec.ProtocolCodecException
Throws:
org.apache.mina.filter.codec.ProtocolCodecException

equals

public boolean equals(Object object)
Overrides:
equals in class Object

equals

public boolean equals(Keys keys)

hashCode

public int hashCode()
Overrides:
hashCode in class Object


Copyright © 2008 Matthew Phillips. All Rights Reserved.