mChaRM.multichannel
Class channelCore

java.lang.Object
  |
  +--uka.karmi.rmi.server.RemoteObject
        |
        +--uka.karmi.rmi.server.UnicastRemoteObject
              |
              +--mChaRM.multichannel.channelCore
All Implemented Interfaces:
channelInterface, java.lang.Cloneable, uka.karmi.rmi.Remote
Direct Known Subclasses:
normalChannel, RMPChannel, validationChannel, verboseChannel

public class channelCore
extends uka.karmi.rmi.server.UnicastRemoteObject
implements channelInterface

This class defines how multi-channels behave (by default) in the abstract locus. Any other kind of multi-channel can be derived from this class. The key issue consists in overriding the coreMetaBehavior method.


Remember each multi-channel is identified by its kind, ie., the reflective behaviour it realizes, and by the set of objects -- playing the role of receivers -- which it is connected to.

Since:
Version 1.0
Version:
1.5
Author:
Walter Cazzola (cazzola@disi.unige.it)

Fields inherited from class uka.karmi.rmi.server.RemoteObject
serverRef
 
Constructor Summary
channelCore(java.lang.String kind, java.lang.String[] RsName, java.lang.String SSClassName, java.lang.String RSClassName)
          constructor of multi-channels.
 
Method Summary
 java.lang.Object coreMetaBehavior(mChaRMMethodCall msg)
          This method embodies the reflective behaviour realized by the multi-channel.
 int howManyReceivers()
          returns the number of receivers bound to this multi-channel.
 int howManySenders()
          returns the number of senders bound to this multi-channel, at the moment of the call.
 java.lang.String kind()
          returns the kind of the multi-channel.
 java.lang.String receiverName(int indx)
          returns the name of the receiver whose position is specified by indx.
 receiverStubInterface receiverStub(java.lang.String name)
           
 receiverStubInterface receiverStubByPosition(int indx)
           
 java.lang.String receiverStubClassName()
           
 java.lang.Object retrieveReceiverFieldValue(java.lang.String receiverName, java.lang.String fieldName)
          retrieves the content of a field of the specified receiver.
 java.lang.Object retrieveSenderFieldValue(java.lang.String senderName, java.lang.String fieldName)
          retrieves the content of a field of the specified sender.
 java.lang.String senderName(int indx)
          returns the name of the sender whose position is specified by indx.
 senderStubInterface senderStub(java.lang.String name)
           
 senderStubInterface senderStubByPosition(int indx)
           
 java.lang.String senderStubClassName()
           
 void senderStubHasBeenCreated(java.lang.String senderStubName)
          the invocation of this method allows to connect the multi-channel to the new stub.
 void setKind(java.lang.String k)
          sets the kind of the multi-channel to the passed value k.
 void setReceiverName(int indx, java.lang.String name)
          inserts the name of a receiver at the position specified by indx.
 void setReceiverStub(java.lang.String name, receiverStubInterface RSI)
           
 void setReceiverStubClassName(java.lang.String name)
           
 void setRsName(java.lang.String[] names)
          uses the array of strings specified by name as the set of names of the receivers of the multi-channel.
 void setSenderName(int indx, java.lang.String name)
          inserts the name of a sender at the position specified by indx.
 void setSenderStub(java.lang.String name, senderStubInterface SSI)
           
 void setSenderStubClassName(java.lang.String name)
           
 java.lang.String supplyASenderStub()
          on request, it supplies the class name of its senderStub to the requiring client.
 
Methods inherited from class uka.karmi.rmi.server.UnicastRemoteObject
buildStub, clone, exportObject, exportObject, unexportObject
 
Methods inherited from class uka.karmi.rmi.server.RemoteObject
equals, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

channelCore

public channelCore(java.lang.String kind,
                   java.lang.String[] RsName,
                   java.lang.String SSClassName,
                   java.lang.String RSClassName)
            throws uka.karmi.rmi.RemoteException,
                   ReceiverStubNotFoundException
constructor of multi-channels.
This constructor creates and registers as server the core of a multi-channel of kind: kind. The core is registered using the following string:
"__"+kind+"{ "rec1+" "+rec2 ... +recn+" }"
then, it instructs each receivers to create and to register as server their stubs. The stub of the receiver reci is registered as:
"__"+kind+"{ "rec1+" "+rec2 ... +recn+" }"+"__"+reci
finally the core connect itself with its stubs on the receivers site.
Parameters:
kind - a String representing the multi-channel's behavior.
RsName - an Array of Strings representing the name of the receivers, which it is connected to.
SSClassName - a String specifying the class of the stubs that will be attached to the multi-channel senders.
RSClassName - a String specifying the class of the stubs that will be attached to the multi-channel receivers.
Throws:
ReceiverStubNotFoundException - thrown when one of the specified receiver wasn't started before the core.
Method Detail

kind

public java.lang.String kind()
returns the kind of the multi-channel.
Returns:
the kind of the multi-channel.

setKind

public final void setKind(java.lang.String k)
sets the kind of the multi-channel to the passed value k.
Parameters:
k - the kind of the multi-channel.

receiverName

public final java.lang.String receiverName(int indx)
returns the name of the receiver whose position is specified by indx. The position is related to how the names are stored. At the moment this method can be used consistently only in conjunction with loop statements.
Parameters:
indx - the index of the position.
Returns:
the name of the receiver.

setReceiverName

public final void setReceiverName(int indx,
                                  java.lang.String name)
inserts the name of a receiver at the position specified by indx.
The method doesn't check if the slot is already used.
Note that you have to keep the set of the name alphabetically sorted in order to allow the core to connect to its stubs and vice versa.
Parameters:
indx - the index of the position.
name - the name of the receiver.

setRsName

public final void setRsName(java.lang.String[] names)
uses the array of strings specified by name as the set of names of the receivers of the multi-channel. It also sorts the array.
Parameters:
names - a set of names.

howManyReceivers

public final int howManyReceivers()
returns the number of receivers bound to this multi-channel.
The number of receivers is a quantities fixed at compile-time and depends on the kinds statement.
Returns:
the number of receivers.

senderName

public final java.lang.String senderName(int indx)
                                  throws java.lang.ArrayIndexOutOfBoundsException
returns the name of the sender whose position is specified by indx.
The position is related to how the names are stored. At the moment this method can be used consistently only in conjunction with loop statements.
Parameters:
indx - the index of the position.
Returns:
the name of the sender.
Throws:
java.lang.ArrayIndexOutOfBoundsException - thrown when the index passed is too big with respect to the number of the senders.

setSenderName

public final void setSenderName(int indx,
                                java.lang.String name)
                         throws java.lang.ArrayIndexOutOfBoundsException
inserts the name of a sender at the position specified by indx.
The method doesn't check if the slot is already used. The method provides to append a new sender to the tail when the current number of sender is passed as index.
Parameters:
indx - the index of the position.
name - the name of the receiver.

howManySenders

public final int howManySenders()
returns the number of senders bound to this multi-channel, at the moment of the call.
The number of senders is zero at the core creation and increase during the execution with the calls the core has to process.
Returns:
the number of senders.

receiverStub

public final receiverStubInterface receiverStub(java.lang.String name)

receiverStubByPosition

public final receiverStubInterface receiverStubByPosition(int indx)

setReceiverStub

public final void setReceiverStub(java.lang.String name,
                                  receiverStubInterface RSI)

senderStub

public final senderStubInterface senderStub(java.lang.String name)

senderStubByPosition

public final senderStubInterface senderStubByPosition(int indx)

setSenderStub

public final void setSenderStub(java.lang.String name,
                                senderStubInterface SSI)

receiverStubClassName

public final java.lang.String receiverStubClassName()

setReceiverStubClassName

public final void setReceiverStubClassName(java.lang.String name)

senderStubClassName

public final java.lang.String senderStubClassName()

setSenderStubClassName

public final void setSenderStubClassName(java.lang.String name)

coreMetaBehavior

public java.lang.Object coreMetaBehavior(mChaRMMethodCall msg)
                                  throws MethodDoesNotExistException,
                                         uka.karmi.rmi.RemoteException
This method embodies the reflective behaviour realized by the multi-channel.
This method performs meta-computations on the reified method call:
multiRMI(RsName, methodName, args)
the computations performed can't make assumption about where their are performed.
This method must be overrode in order to implement new kind of multi-channels.

as default behavior, it delivers the message to the specified receivers, collects the results and returns the result of the computation of the first receiver to the sender.
Note that receivers can be a subset of the multi-channel's receivers
Specified by:
coreMetaBehavior in interface channelInterface
Parameters:
msg - the hijacked method call.
Returns:
the result of the method call.
Throws:
MethodDoesNotExistException - thrown when the method reified doesn't exist in the referent class.

retrieveSenderFieldValue

public java.lang.Object retrieveSenderFieldValue(java.lang.String senderName,
                                                 java.lang.String fieldName)
                                          throws SenderStubNotFoundException,
                                                 FieldDoesNotExistException,
                                                 uka.karmi.rmi.RemoteException
retrieves the content of a field of the specified sender.
Parameters:
senderName - the name of the sender the core questions about the content of its field
fieldName - the name of the field we want to inspect.
Returns:
the content of the inspected field.
Throws:
SenderStubNotFoundException - thrown when the sender is unreacheable.
FieldDoesNotExistException - thrown when the class of the sender doesn't define the field passed.

retrieveReceiverFieldValue

public java.lang.Object retrieveReceiverFieldValue(java.lang.String receiverName,
                                                   java.lang.String fieldName)
                                            throws ReceiverStubNotFoundException,
                                                   FieldDoesNotExistException,
                                                   uka.karmi.rmi.RemoteException
retrieves the content of a field of the specified receiver.
Parameters:
receiverName - the name of the receiver the core questions about the content of its field
fieldName - the name of the field we want to inspect.
Returns:
the content of the inspected field.
Throws:
ReceiverStubNotFoundException - thrown when the receiver is unreacheable.
FieldDoesNotExistException - thrown when the class of the sender doesn't define the field passed.

supplyASenderStub

public final java.lang.String supplyASenderStub()
                                         throws uka.karmi.rmi.RemoteException
on request, it supplies the class name of its senderStub to the requiring client.
when a sender needs that one of its computation be reified by a multi-channel it looks for a sender stub of such multi-channel.
This method cannot be overrode nor used directly by users.
returns: the class name of its senderStub.
Specified by:
supplyASenderStub in interface channelInterface

senderStubHasBeenCreated

public final void senderStubHasBeenCreated(java.lang.String senderStubName)
                                    throws SenderStubNotFoundException
the invocation of this method allows to connect the multi-channel to the new stub.
This method cannot be overrode nor used directly by users.
Specified by:
senderStubHasBeenCreated in interface channelInterface
Parameters:
senderStubName - the name of the stub, who the multi-channel have to connect to.
Throws:
SenderStubNotFoundException - thrown when the senderStub is not ready to be linked to the core.