de.tubs.macs.util.net
Class NetManager

java.lang.Object
  |
  +--de.tubs.macs.util.net.NetManager

public class NetManager
extends java.lang.Object

Network Manager.

This class provides methods to

the supported networks, its class names and default options are defined in the resourcefile

a net implemantation has to provide the following classes:

this example shows the properties with to supported networks (TCP and LRMP)

 net.types=lrmp tcp

 tcp.name=TCP Network
 tcp.group=localhost/9999
 tcp.options=centralized
 tcp.netclass=de.tubs.macs.util.net.TCP
 tcp.addressclass=de.tubs.macs.util.net.TCPAddress
 tcp.dialogclass=de.tubs.macs.util.net.TCPDialog

 lrmp.name=LRMP Network
 lrmp.group=225.000.000.000/7000
 lrmp.options=15/100
 lrmp.netclass=de.tubs.macs.util.net.LRMP
 lrmp.addressclass=de.tubs.macs.util.net.LRMPAddress
 lrmp.dialogclass=de.tubs.macs.util.net.LRMPDialog
 

Author:
Heiner Grote

Field Summary
(package private)  Debug debug
          the debug class and its key string
(package private) static Log log
          access to log for this class
(package private) static Resource resource
          Resource object
 
Constructor Summary
protected NetManager(Resource resource, Log log)
          creates a new NetManager.
 
Method Summary
 boolean addAddress(NetAddress address)
          add a new address to the set of used addresses.
 boolean addressUsed(NetAddress address)
          address used ?
 boolean addressUsed(java.lang.String type, java.lang.String group)
          address used ?
 NetAddress createAddress(java.lang.String type)
          creates an address for the given network type and adds it to the set of used addresses
 NetAddress createAddress(java.lang.String type, java.lang.String label)
          creates an address for the given network type and adds it to the set of used addresses
 NetAddress createAddress(java.lang.String type, java.lang.String group, java.lang.String options)
          creates an address for the given network type and adds it to the set of used addresses
 void delAddress(NetAddress address)
          remove an address from the set of used addresses.
 NetAddress getAddress(java.lang.String type, java.util.Hashtable dialogs)
           
 NetAddress getAddress(java.lang.String type, java.lang.String group)
          Retrieve an address from the set of used addresses.
 NetAddress getAddress(java.lang.String type, java.lang.String name, java.util.Hashtable dialogs)
          Retrieve an address from a dialog.
 java.lang.String getName(java.lang.String type)
          returns a name of the network type for use in NetSelectorPanel.
 Net getNet(NetReceiver receiver, NetAddress group)
          creates a new Net instance for the given group.
static NetManager getNetManager()
          returns the NetManager reference.
static NetManager getNetManager(Resource res)
          creates a NetManager if not yet done and returns a reference on this
static NetManager getNetManager(Resource res, Log l)
          creates a NetManager if not yet done and returns a reference on this
 java.util.Enumeration getNetworks()
          returns the enumeration of network-IDs (Strings) of the availabale networks.
 void showNetDialog(java.lang.String type, java.util.Hashtable dialogs)
           
 void showNetDialog(java.lang.String type, java.lang.String name, java.util.Hashtable dialogs)
          show the setup dialog for NetAddresses of the given type
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

resource

static Resource resource
Resource object

log

static Log log
access to log for this class

debug

Debug debug
the debug class and its key string
Constructor Detail

NetManager

protected NetManager(Resource resource,
                     Log log)
creates a new NetManager. NetManager is a singleton so this constructor is protected! Use NetManager.getNetManager(Resource resource) once to create it and NetManager.getNetManager() to get an reference.
Method Detail

getNetManager

public static NetManager getNetManager(Resource res,
                                       Log l)
creates a NetManager if not yet done and returns a reference on this
Parameters:
resource - a resource object holding infos about available networks
log - a log object (if null a new log object is created)
Returns:
the NetManager

getNetManager

public static NetManager getNetManager(Resource res)
creates a NetManager if not yet done and returns a reference on this
Parameters:
resource - a resource object holding infos about available networks
Returns:
the NetManager

getNetManager

public static NetManager getNetManager()
returns the NetManager reference. the NetManager has to be created with getNetManager(Resource resource) or getNetManager(Resource resource, Log log) before using this, else this method will create a fatal log entry.
Returns:
the NetManager

getNetworks

public java.util.Enumeration getNetworks()
returns the enumeration of network-IDs (Strings) of the availabale networks.

getName

public java.lang.String getName(java.lang.String type)
returns a name of the network type for use in NetSelectorPanel.
Parameters:
type - type of the Network
Returns:
the name of the Network (e.g. "TCP Network")

createAddress

public NetAddress createAddress(java.lang.String type)
                         throws NetException
creates an address for the given network type and adds it to the set of used addresses
Parameters:
type - the type of the network (tcp, lrmp, ...)

createAddress

public NetAddress createAddress(java.lang.String type,
                                java.lang.String label)
                         throws NetException
creates an address for the given network type and adds it to the set of used addresses
Parameters:
type - the type of the network (tcp, lrmp, ...)
label - the label for this address (optional, application specific)

createAddress

public NetAddress createAddress(java.lang.String type,
                                java.lang.String group,
                                java.lang.String options)
                         throws NetException
creates an address for the given network type and adds it to the set of used addresses
Parameters:
type - the type of the network (tcp, lrmp, ...)
options - options to be used for networks whith this address
group - a string representation from a NetAddress of the given type
Returns:
the new address or null if creation fails

getAddress

public NetAddress getAddress(java.lang.String type,
                             java.lang.String group)
Retrieve an address from the set of used addresses. Returns null, if address is unused yet
Parameters:
group - a string representation from a NetAddress of the given type
type - the type of the network (tcp, lrmp, ...)
Returns:
the found NetAddress

getAddress

public NetAddress getAddress(java.lang.String type,
                             java.lang.String name,
                             java.util.Hashtable dialogs)
                      throws NetException
Retrieve an address from a dialog. The dialogs are given by a Hashtable. You have to use the Hashtable managed by showNetDailog() !

If there is no dialog for the given type or the address from that dialog is not valid (e.g. already used somewhere else) a new address will be created and returned by calling createAddress(type). That means that you can use this method even when the user hasn't used any dialog yet.

see showNetDialog() for more details on dialogs.

Parameters:
type - the type of the network (tcp, lrmp, ...)
name - the name given for the dialog used to edit this address
dialogs - a Hashtables that contains the dialogs.
Returns:
the address

getAddress

public NetAddress getAddress(java.lang.String type,
                             java.util.Hashtable dialogs)
                      throws NetException

addAddress

public boolean addAddress(NetAddress address)
add a new address to the set of used addresses.
Parameters:
address - the NetAddress to add
Returns:
false, if address was used already

delAddress

public void delAddress(NetAddress address)
remove an address from the set of used addresses.
Parameters:
address - the NetAddress to remove

addressUsed

public boolean addressUsed(NetAddress address)
address used ?
Parameters:
address - the NetAddress to look for
Returns:
true, if set of used addresses contains the given address

addressUsed

public boolean addressUsed(java.lang.String type,
                           java.lang.String group)
address used ?
Parameters:
group - a string representation from a NetAddress of the given type
type - the type of the network (tcp, lrmp, ...)
Returns:
true, if set of used addresses contains the given address

getNet

public Net getNet(NetReceiver receiver,
                  NetAddress group)
           throws NetException
creates a new Net instance for the given group. the type of the network is given through the type of the given NetAddress. The options are taken from the address.
Parameters:
receiver - a NetReceiver which receives the Object
group - the address of the network group
Throws:
NetException - when creation of network fails

showNetDialog

public void showNetDialog(java.lang.String type,
                          java.lang.String name,
                          java.util.Hashtable dialogs)
show the setup dialog for NetAddresses of the given type

when first calling this method use an empty Hashtable as parameter dialogs and use this Hashtable for each later call of this method.
showNetDialog() will create the dialogs and store them for reuse into that Hashtable.

Use getAddress(type, Hashtable) to get/create addresses when you are using dialogs.

Following example shows the typical usage of NetDialogs

 Hashtable dialogs = new Hashtable();


 // getting an address 
 NetAddress address = null;
 String networkID = ... (network type);
 
 try {
   // get address from gialog
   address = (NetAddress)netManager.getAddress(networkID, dialogs);
 } catch (NetException ne) {
   ... handle Exception
 }


 // displaying a dialog
 String networkID = ...(network type);
 netManager.showNetDialog(networkID, dialogs);
 
Parameters:
type - the type of the network to create a dialog for
name - a name for the dialog
dialogs - the dialogs in a Hashtable (key: "type_name")
Returns:
a handle for the dialog

showNetDialog

public void showNetDialog(java.lang.String type,
                          java.util.Hashtable dialogs)