Implementing the File ServerChannel Class

FileServerChannel is the main class for our server-side processing. It has the following responsibilities:

• Listening for incoming messages

• Creating a formatter sink

• Creating a FileServerChannelSink

• Building the sink chain

As we discuss the construction of FileServerChannel, we'll take extra care in addressing these items.

FileServerChannel will be receiving messages; therefore, it must implement IChannelReceiver. Because IChannelReceiver implements IChannel, we must add three new members to FileServerChannel: ChannelName, ChannelPriority, and Parse. To support IChannelReceiver functionality, we must add the members ChannelData, GetUrlsForUri, StartListening, and StopListening. Let's start by examining the public interface of FileServerChannel:

public class FileServerChannel : IChannelReceiver {

public FileServerChannel( String serverPath ){ ... }

public FileServerChannel( IDictionary properties,

IServerChannelSinkProvider provider )

// IChannel members public String Parse( String url, out String objectURI ){ ... } public String ChannelName{ ... } public int ChannelPriority{ ... } // IChannelReceiver members public void StartListening( Object data ){ ... } public void StopListening( Object data ){ ... }

public String[] GetUrlsForUri ( String objectURI ){ ... }

public Object ChannelData{ ... }

As with FileClientChannel, FileServerChannel has two constructors. The first is a simple constructor that sets the private member variable m_ServerPath to the value passed into the constructor and calls the private method Init. The m_ServerPath variable designates which directory the server will watch for files.

The second constructor will allow for more granularity in the FileServerChannel settings. Like the first constructor, it must also call Init.

public FileServerChannel( IDictionary properties,

IServerChannelSinkProvider provider )

m_SinkProvider = provider;

foreach (DictionaryEntry entry in properties) {

switch ((String)entry.Key) {

case "name":

m_ChannelName = ( String ) entry.Value; break; case "priority":

m_ChannelPriority = ( int ) entry.Value; break; case "serverpath":

m_ServerPath = ( String ) entry.Value; break;

// Since the FileChannel constructor that calls this constructor // creates both the FileClientChannel and FileServerChannel // objects, we must check the m_ServerPath to see if we should // listen for incoming messages.

0 0

Post a comment