Main Page | Packages | Class Hierarchy | Compound List | Compound Members

de.stz.bt.fnd.FND_DataPointContext Class Reference

Inheritance diagram for de.stz.bt.fnd.FND_DataPointContext:

de.stz.bt.framework.DataPointContext de.stz.bt.fnd.datapoints.api.FND_DatapointService List of all members.

Public Member Functions

 FND_DataPointContext (Element config)
void init ()
FND_DatagramFactory getDatagramFactory ()
FND_DataPointFactory getDataPointFactory ()
int getContextControlType ()
InetAddress getTarget ()
List enumerateAllDatapoints ()
FND_MessagePoint getMessagePoint (String dpid)
FND_SwitchPoint getSwitchPoint (String dpid)
FND_MeasurePoint getMeasurePoint (String dpid)
FND_SetPoint getSetPoint (String dpid)
FND_TransferPoint getTransferPoint (String dpid)
FND_CollectAddressPoint getCollectAddresspoint (String dpid)

Static Public Attributes

final int CENTRAL = 0
final int ISLAND = 1

Protected Member Functions

synchronized void handleNORMALDatagram (FND_Datagram dgram) throws Exception
synchronized void handleREJECTDatagram (FND_Datagram dgram)
synchronized void handleERRORDatagram (FND_Datagram dgram)
void sendDatagram (FND_Datagram out)

Protected Attributes

String URL_PREFIX = ""
FND_DatagramFactory dgramFactory
FND_DataPointFactory dpFactory
LinkedHashMap datapoints = new LinkedHashMap()

Detailed Description

Represents the container for datapoint opbjects and message infrastructure The FND_DatapointContext is the runtime environment for datapoints. Each datapoint running on an either an island control or on an central control needs a set of common parameters and services that are provided by an datapoint context. The context offer the following services:

A datagram has a source and a drain. It is sourced either by API Interaction with a datapoint, or by a datagram received through an outside interface like the UDPServer. The Datagram Factory provides the source, and should in the future also be the sink and contain a datagram pool for deterministic memory consumption

Author:
J. Seitter
Version:
$Id: FND_DataPointContext.java,v 1.4 2004/10/17 21:45:40 jseitter Exp $


Constructor & Destructor Documentation

de.stz.bt.fnd.FND_DataPointContext.FND_DataPointContext Element  config  ) 
 

Default Constructor. Set the configuration Element and detaches it from its Tree.

00126                                               {
00127     this.config = (Element) config.clone();
00128     this.config.detach();
00129     dpFactory.setContext(this);
00130   }


Member Function Documentation

int de.stz.bt.fnd.FND_DataPointContext.getContextControlType  ) 
 

Returns:
The current control type, either CENTRAL or ISLAND

00478                                      {
00479     return contextControlType;
00480   }

FND_DatagramFactory de.stz.bt.fnd.FND_DataPointContext.getDatagramFactory  ) 
 

Returns:
a reference to the datagram factory belonging to this context.

00201                                                   {
00202     return dgramFactory;
00203   }

FND_DataPointFactory de.stz.bt.fnd.FND_DataPointContext.getDataPointFactory  )  [virtual]
 

Returns:
a reference to the datapoint factory belonging to this context.

Implements de.stz.bt.framework.DataPointContext.

00208                                                     {
00209     return dpFactory;
00210   }

InetAddress de.stz.bt.fnd.FND_DataPointContext.getTarget  ) 
 

Returns:
the target InetAddress for this context at the moment contexts support only a single target

00502                                  {
00503     return target;
00504   }

synchronized void de.stz.bt.fnd.FND_DataPointContext.handleERRORDatagram FND_Datagram  dgram  )  [protected]
 

this method handles error datagrams Only ISLAND contexts can send error datagrams, son only CENTRAL contexts have to handle them

Parameters:
the error datagram

00465                                                                       {
00466 
00467     byte d_r = dgram.getTransportControl()[0];
00468 
00469     if (d_r == FND_Datagram.D_R_CMD || d_r == FND_Datagram.D_R_USM) {
00470       logger.warn("invalid ERROR datagram --> discarded");
00471     }
00472     logger.warn("Last datagram has caused an ERROR datagram ");
00473   }

synchronized void de.stz.bt.fnd.FND_DataPointContext.handleNORMALDatagram FND_Datagram  dgram  )  throws Exception [protected]
 

handles a normal datagram. In this method we have to diffenratiate the type of the datagram and check if this context is responsible for handling it with one of it's datapoints

00309                        {
00310 
00311     // get the datapoint address from the datagram
00312     byte[] dp_id = dgram.getDataPointID();
00313     logger.debug("Context: got NORMAL datagram");
00314     logger.debug("for DP ID: " + new String(dp_id));
00315 
00316     //This checks if a datapoint with the given ID exists, else creates
00317     // one.
00318     // This should be optional by adding a flag in the config
00319     if (!datapoints.containsKey(URL_PREFIX + new String(dp_id).trim())) {
00320       dpFactory.createDataPointFromDatagram(dgram);
00321     }
00322 
00323     // TODO: very big mistake! we create a datapoint and afterwards it
00324     // happens that we don't want to handle it.
00325     // we have to encapsulate this code and execute it from each of the
00326     // select
00327     // methods below !!!!!
00328 
00329     // Finally we get the datapoint (have to handle exceptions if dp is not
00330     // auto-created)
00331     FND_DataPoint dp = (FND_DataPoint) datapoints.get(URL_PREFIX
00332         + new String(dp_id).trim());
00333 
00334     // ---
00335     dp.setLastAccessTime();
00336     if (dgram.getDatapointType() != dp.getDp_type()) {
00337       logger
00338           .warn("datapoint type and adressed type mismatch --> rejecting datagram");
00339       sendDatagram(dgramFactory.getREJECTDatagram(dgram));
00340     } else {
00341       //TODO: check for convinience method
00342       byte d_r = dgram.getTransportControl()[0];
00343       FND_Datagram result = null;
00344       switch (d_r) {
00345 
00346       //This is executed if we receive a cmd
00347       //happens only on islands
00348       // we have to put the
00349       // invoke id into the receive pool
00350       // we check this and reject if needed
00351       case FND_Datagram.D_R_CMD:
00352         // TODO: handle invoke_id
00353         //If this is a central context we do handle no CMD
00354         if (this.contextControlType == FND_DataPointContext.CENTRAL) {
00355           logger
00356               .warn("central context can not handle CMD datagrams --> rejecting");
00357           result = dgramFactory.getREJECTDatagram(dgram);
00358           sendDatagram(result);
00359         } else {
00360           logger.debug("handle CMD datagram");
00361           logger
00362               .debug("SHORTCUT: I just return a response datagram and put into queue");
00363           // we set the busy flag on the datapoint for thread
00364           // synchronization
00365           logger.debug("locking datapoint");
00366           dp.lockDP(); // the lock is reset from within an datapoint
00367 
00368           result = dp.handleCMDDatagram(dgramFactory
00369               .getRSPDatagram(dgram));
00370           sendDatagram(result);
00371         }
00372         break;
00373 
00374       // This is executed if we receive a RSP datagram.
00375       // Happens only on centrals
00376       // 
00377       case FND_Datagram.D_R_RSP:
00378         //TODO: handle invoke_id
00379         // If this is a island context we do handle no RSP
00380         if (this.contextControlType == FND_DataPointContext.ISLAND) {
00381           logger
00382               .warn("island context can not handle RSP --> rejecting");
00383           result = dgramFactory.getREJECTDatagram(dgram);
00384           sendDatagram(result);
00385         } else {
00386           logger.debug("handle RSP datagram");
00387           // we set the busy flag on the datapoint for thread
00388           // synchronization
00389           logger.debug("locking datapoint");
00390           dp.lockDP(); // the lock is reset from within an datapoint
00391 
00392           dp.handleRSPDatagram(dgram);
00393         }
00394 
00395       case FND_Datagram.D_R_USM:
00396         //  If this is a island context we do handle no USM
00397         //  TODO: handle invoke_id
00398         if (this.contextControlType == FND_DataPointContext.ISLAND) {
00399           logger
00400               .warn("island context can not handle USM --> rejecting");
00401           result = dgramFactory.getREJECTDatagram(dgram);
00402           sendDatagram(result);
00403         } else {
00404           logger.debug("handle USM datagram");
00405           // we set the busy flag on the datapoint for thread
00406           // synchronization
00407           logger.debug("locking datapoint");
00408           dp.lockDP(); // the lock is reset from within an datapoint
00409 
00410           result = dp.handleUSMDatagram(dgramFactory
00411               .getACKDatagram(dgram));
00412           sendDatagram(result);
00413         }
00414         break;
00415 
00416       case FND_Datagram.D_R_ACK:
00417         //  TODO: handle invoke_id
00418         // If this is a central context we do handle no ACK
00419         if (this.contextControlType == FND_DataPointContext.CENTRAL) {
00420           logger
00421               .warn("central context does not handle ACK --> rejecting");
00422           result = dgramFactory.getREJECTDatagram(dgram);
00423           sendDatagram(result);
00424         } else {
00425           logger.debug("handle ACK datagram");
00426           // we set the busy flag on the datapoint for thread
00427           // synchronization
00428           logger.debug("locking datapoint");
00429           dp.lockDP(); // the lock is reset from within an datapoint
00430 
00431           dp.handleACKDatagram(dgram);
00432           // an ACK does not have a result
00433           //sendDatagram(result);
00434         }
00435         break;
00436       }
00437 
00438     }
00439 
00440   }

synchronized void de.stz.bt.fnd.FND_DataPointContext.handleREJECTDatagram FND_Datagram  dgram  )  [protected]
 

this method handles reject datagrams

Parameters:
dgram 

00447                                                                        {
00448 
00449     byte d_r = dgram.getTransportControl()[0];
00450 
00451     if (d_r == FND_Datagram.D_R_CMD || d_r == FND_Datagram.D_R_USM) {
00452       logger.warn("invalid REJECT datagram --> discarded");
00453     }
00454     logger.warn("Last datagram has been REJECTed");
00455 
00456   }

void de.stz.bt.fnd.FND_DataPointContext.init  ) 
 

After creating the object it has to be initialized by calling this method.

00152                      {
00153 
00154     // create a datapoint object for each declared datapoint
00155     createDatapoints(config.getChildren("datapoint"));
00156 
00157     String mode = config.getAttributeValue("mode");
00158     if (mode.equals("CENTRAL")) {
00159       setContextControlType(CENTRAL);
00160       logger.debug("Context Mode:CENTRAL");
00161     }
00162     if (mode.equals("ISLAND")) {
00163       setContextControlType(ISLAND);
00164       logger.debug("Context Mode:ISLAND");
00165     }
00166 
00167     URL_PREFIX = config.getAttributeValue("prefix")
00168         + config.getAttributeValue("id") + "/";
00169     logger.debug("context prefix: " + URL_PREFIX);
00170 
00171     // setting the peer IP Address
00172     try {
00173       target = InetAddress.getByName(config.getChild("transport")
00174           .getAttributeValue("target"));
00175       logger.debug("target ip=" + target.getHostAddress());
00176     } catch (UnknownHostException e1) {
00177       logger.error("Target Host is unknown :(", e1);
00178     }
00179     try {
00180       // reference context from server
00181       this.fndUDPServer = new FND_UDPTransport(this);
00182     } catch (SocketException e) {
00183       logger.error("socket error", e);
00184     } catch (IOException e) {
00185       // TODO Auto-generated catch block
00186       logger.error("IOException",e);
00187       e.printStackTrace();
00188     }
00189 
00190     fndUDPServer.start();
00191 
00192     //create the worker thread, later we can have more than one worker
00193     FND_ContextThread t = new FND_ContextThread(this);
00194     t.start();
00195 
00196   }


Member Data Documentation

FND_DatagramFactory de.stz.bt.fnd.FND_DataPointContext.dgramFactory [protected]
 

Initial value:

 FND_DatagramFactory
      .getInstance()

FND_DataPointFactory de.stz.bt.fnd.FND_DataPointContext.dpFactory [protected]
 

Initial value:

 FND_DataPointFactory
      .getInstance()


The documentation for this class was generated from the following file:
Generated on Mon Nov 15 08:36:10 2004 for FND4J by doxygen 1.3.3