com.sun.sgs.impl.service.channel
Class ChannelImpl

java.lang.Object
  extended by com.sun.sgs.impl.service.channel.ChannelImpl
All Implemented Interfaces:
ManagedObject, Serializable

final class ChannelImpl
extends Object
implements ManagedObject, Serializable

Channel implementation for use within a single transaction.

This implementation uses several BindingKeyedCollections as follows:

Map: channelsMap
Prefix: "com.sun.sgs.impl.service.channel.name."
Key: name
Value: ChannelImpl
Map for accessing a ChannelImpl by name.

Map: eventQueuesMap
Prefix: "com.sun.sgs.impl.service.channel.eventQueue."coordinatorNodeId.
Key: channelId (as string form of BigInteger)
Value: EventQueue
Map for accessing an event queue for a channel on a given node. The map is also used during recovery to determine which channels are coordinated on a failed node so that each channel can be reassigned a new coordinator.

Map: savedMessagesMap
Prefix: "com.sun.sgs.impl.service.channel.message."channelId.
Key: timestamp (as string form of Long)
Value: ChannelMessageInfo
Map for accessing saved messages for a given channel by timestamp. The map is used when a client session relocates to a new node and the channel service discovers that the session missed one or more channel messages during relocation.


Nested Class Summary
(package private) static class ChannelImpl.ChannelEvent
          Represents an event on a channel.
(package private) static class ChannelImpl.ChannelMessageInfo
          Contains a saved channel message with its associated timestamp and expiration time.
(package private) static class ChannelImpl.ReassignCoordinatorsTask
          A persistent task to reassign channel coordinators on a failed node to another node.
(package private) static class ChannelImpl.RemoveFailedNodeFromLocalChannelsTask
          A persistent task to remove a failed node, from locally coordinated channels.
(package private) static class ChannelImpl.SendEvent
          A channel send event.
 
Field Summary
(package private)  BigInteger channelRefId
          The ID from a managed reference to this instance.
(package private) static String CHANNELS_MAP_PREFIX
          The channels map prefix.
(package private) static Set<BigInteger> EMPTY_CHANNEL_MEMBERSHIP
          The empty channel membership set.
(package private) static String EVENT_QUEUE_MAP_PREFIX
          An event queue map prefix.
(package private) static String SAVED_MESSAGES_MAP_PREFIX
          The saved messages map prefix.
 
Method Summary
(package private)  void addServerNodeId(long nodeId)
          Adds the specified nodeId to the set of server nodes for this channel.
(package private)  void close(boolean removeName)
          Enqueues a close event to this channel's event queue and notifies this channel's coordinator to service the event.
 boolean equals(Object obj)
          
(package private)  List<ChannelImpl.ChannelMessageInfo> getChannelMessages(long fromTimestamp, long toTimestamp)
          Returns a list containing saved channel messages (if any) with timestamps between fromTimestamp and toTimestamp inclusive.
(package private)  long getCurrentMessageTimestamp()
          Returns the message timestamp of the last message processed by this channel.
(package private)  Delivery getDelivery()
          Implements Channel.getDelivery().
(package private) static Channel getInstance(String name)
          Returns a channel with the given name.
(package private)  String getName()
          Implements Channel.getName().
(package private)  Iterator<ClientSession> getSessions()
          Implements Channel.getSessions().
(package private) static void handleChannelMessage(BigInteger channelRefId, ClientSession sender, ByteBuffer message)
          Handles a channel message that the specified sender is sending on the channel with the specified channelRefId.
 int hashCode()
          
(package private)  boolean hasSessions()
          Implements Channel.hasSessions().
(package private)  boolean isClosed()
          Returns true if the channel is closed, and false otherwise.
(package private)  boolean isCoordinator()
          Returns true if this node is the coordinator for this channel, otherwise returns false.
(package private)  void join(ClientSession session)
          Implements Channel.join(ClientSession).
(package private)  void join(Set<? extends ClientSession> sessions)
          Implements Channel.join(Set).
(package private)  void leave(ClientSession session)
          Implements Channel.leave(ClientSession).
(package private)  void leave(Set<? extends ClientSession> sessions)
          Implements Channel.leave(Set).
(package private)  void leaveAll()
          Implements Channel.leaveAll().
(package private) static Channel newInstance(String name, ChannelListener listener, Delivery delivery, int writeBufferCapacity)
          Constructs a new Channel with the given name, listener, delivery guarantee and write-buffer capacity.
(package private)  void removeServerNodeId(long nodeId)
          Removes the specified nodeId from the set of server nodes for this channel.
(package private)  void send(ClientSession sender, ByteBuffer message)
          Implements Channel.send(ClientSession,ByteBuffer).
(package private) static void serviceEventQueue(BigInteger channelRefId)
          Services the event queue for the channel with the specified channelRefId.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

CHANNELS_MAP_PREFIX

static final String CHANNELS_MAP_PREFIX
The channels map prefix.

See Also:
Constant Field Values

EVENT_QUEUE_MAP_PREFIX

static final String EVENT_QUEUE_MAP_PREFIX
An event queue map prefix.

See Also:
Constant Field Values

SAVED_MESSAGES_MAP_PREFIX

static final String SAVED_MESSAGES_MAP_PREFIX
The saved messages map prefix.

See Also:
Constant Field Values

EMPTY_CHANNEL_MEMBERSHIP

static final Set<BigInteger> EMPTY_CHANNEL_MEMBERSHIP
The empty channel membership set.


channelRefId

final BigInteger channelRefId
The ID from a managed reference to this instance.

Method Detail

newInstance

static Channel newInstance(String name,
                           ChannelListener listener,
                           Delivery delivery,
                           int writeBufferCapacity)
Constructs a new Channel with the given name, listener, delivery guarantee and write-buffer capacity.


getInstance

static Channel getInstance(String name)
Returns a channel with the given name.


getName

String getName()
Implements Channel.getName().


getDelivery

Delivery getDelivery()
Implements Channel.getDelivery().


hasSessions

boolean hasSessions()
Implements Channel.hasSessions().


getSessions

Iterator<ClientSession> getSessions()
Implements Channel.getSessions().


join

void join(ClientSession session)
Implements Channel.join(ClientSession).


join

void join(Set<? extends ClientSession> sessions)
Implements Channel.join(Set). Enqueues a join event to this channel's event queue and notifies this channel's coordinator to service the event.


getCurrentMessageTimestamp

long getCurrentMessageTimestamp()
Returns the message timestamp of the last message processed by this channel.

Returns:
the current message timestamp processed by this channel's event queue

leave

void leave(ClientSession session)
Implements Channel.leave(ClientSession). Enqueues a leave event to this channel's event queue and notifies this channel's coordinator to service the event.


leave

void leave(Set<? extends ClientSession> sessions)
Implements Channel.leave(Set). Enqueues leave event(s) to this channel's event queue and notifies this channel's coordinator to service the event(s).


leaveAll

void leaveAll()
Implements Channel.leaveAll(). Closes the current channel, and creates a new channel (with a new channel ID) that uses the existing channel's wrapper. Since the application still uses the same channel wrapper for this channel, the application is not effected.


send

void send(ClientSession sender,
          ByteBuffer message)
Implements Channel.send(ClientSession,ByteBuffer). Enqueues a send event to this channel's event queue and notifies this channel's coordinator to service the event.


close

void close(boolean removeName)
Enqueues a close event to this channel's event queue and notifies this channel's coordinator to service the event. This method is invoked with true by this channel's ChannelWrapper when the application removes the wrapper object, and is invoked with false by this channel when the application invokes the leaveAll() method.

Parameters:
removeName - if true, the channel's name binding is removed when the channel's persistent structures are cleaned up, otherwise, the channel's name binding is not removed

equals

public boolean equals(Object obj)

Overrides:
equals in class Object

hashCode

public int hashCode()

Overrides:
hashCode in class Object

toString

public String toString()

Overrides:
toString in class Object

isClosed

boolean isClosed()
Returns true if the channel is closed, and false otherwise.


isCoordinator

boolean isCoordinator()
Returns true if this node is the coordinator for this channel, otherwise returns false.


addServerNodeId

void addServerNodeId(long nodeId)
Adds the specified nodeId to the set of server nodes for this channel.

Parameters:
nodeId - a server node's ID

removeServerNodeId

void removeServerNodeId(long nodeId)
Removes the specified nodeId from the set of server nodes for this channel.

Parameters:
nodeId - a server node's ID

getChannelMessages

List<ChannelImpl.ChannelMessageInfo> getChannelMessages(long fromTimestamp,
                                                        long toTimestamp)
Returns a list containing saved channel messages (if any) with timestamps between fromTimestamp and toTimestamp inclusive. If fromTimestamp is greater than toTimestamp this method returns null.


handleChannelMessage

static void handleChannelMessage(BigInteger channelRefId,
                                 ClientSession sender,
                                 ByteBuffer message)
Handles a channel message that the specified sender is sending on the channel with the specified channelRefId.

Parameters:
channelRefId - the channel ID, as a BigInteger
sender - the client session sending the channel message
message - the channel message

serviceEventQueue

static void serviceEventQueue(BigInteger channelRefId)
Services the event queue for the channel with the specified channelRefId.


RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved