cdev-1.7.2n

This commit is contained in:
2022-12-13 12:44:04 +01:00
commit b3b88fc333
1357 changed files with 338883 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
# Makefile for RSVC JAVA Package
.SUFFIXES: .class .java
JAVAC = javac
JAVACFLAGS = -O
CLASSOBJS = rsvcException.class \
rsvcDataTypes.class \
rsvcTimeStamp.class \
rsvcDataEntry.class \
rsvcData.class \
rsvcDataOutputStream.class \
rsvcDataInputStream.class \
rsvcConfig.class \
rsvcEvent.class \
rsvcEventHandler.class \
rsvcClient.class \
rsvcClientReader.class \
rsvcUdpClient.class \
rsvcDisplay.class \
rsvcClientTest.class \
rsvcServerTest.class
all: $(CLASSOBJS)
.java.class:
rm -f $@
$(JAVAC) $(JAVACFLAGS) $<
clean:
rm -f *~ core *.class

View File

@@ -0,0 +1,32 @@
//-----------------------------------------------------------------------------
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
// Continuous Electron Beam Accelerator Facility
//
// This software was developed under a United States Government license
// described in the NOTICE file included as part of this distribution.
//
// Jefferson Lab HPC Group, 12000 Jefferson Ave., Newport News, VA 23606
//-----------------------------------------------------------------------------
//
// Description:
//
//
// Author:
// Jie Chen
// Jefferson Lab HPC Group
//
// Revision History:
// $Log: header.java,v $
// Revision 1.1.1.1 2000/05/23 15:12:50 pal
// cdev_psi_1.7.2
//
// Revision 1.1 1999/10/18 17:12:39 chen
// *** empty log message ***
//
// Revision 1.1.1.1 1999/09/07 15:29:10 chen
// CMLOG version 2.0
//
//
//

View File

@@ -0,0 +1,639 @@
//-----------------------------------------------------------------------------
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
// Continuous Electron Beam Accelerator Facility
//
// This software was developed under a United States Government license
// described in the NOTICE file included as part of this distribution.
//
// Jefferson Lab HPC Group, 12000 Jefferson Ave., Newport News, VA 23606
//-----------------------------------------------------------------------------
//
// Description:
// Core part of rsvcClient Java Package
//
// Author:
// Jie Chen
// Jefferson Lab HPC Group
//
// Revision History:
// $Log: rsvcClient.java,v $
// Revision 1.1.1.1 2000/05/23 15:12:50 pal
// cdev_psi_1.7.2
//
// Revision 1.1 1999/10/18 17:12:39 chen
// *** empty log message ***
//
//
//
import rsvcData;
import rsvcEvent;
import rsvcConfig;
import rsvcEventHandler;
import rsvcClientReader;
import java.io.*;
import java.net.*;
import java.util.*;
public final class rsvcClient
{
// connection flag
private boolean connected_ = false;
// Socket to the server
private Socket tcpsocket_ = null;
// server information
private String server_host_ = null;
private int server_port_ = 0;
// internal request id
private int eventid_ = 1234;
// internal client data reader
private rsvcClientReader reader_ = null;
// internal thread id for reader
private Thread readerthread_ = null;
// output stream
private OutputStream output_ = null;
/**
* Construct an empty rsvcClient object
*/
public rsvcClient ()
{
// empty
}
/**
* Override default finalize method.This allows Java virtual
* machine to clean up resource when this object is no longer
* needed.
*/
protected void finalize() throws Throwable
{
if (tcpsocket_ != null && connected_ == true) {
connected_ = false;
tcpsocket_.close ();
}
}
/**
* Connect to a server that is on a given host at a given port
*/
public synchronized void connect (String host, int port) throws UnknownHostException, IOException
{
try {
tcpsocket_ = new Socket (host, port);
}catch (UnknownHostException ue){
System.err.println (ue);
throw ue;
}catch (IOException e) {
System.err.println(e);
throw e;
}
// set connection flag
connected_ = true;
// cache server information
server_host_ = new String(host);
server_port_ = port;
OutputStream toutput = null;
try {
toutput = tcpsocket_.getOutputStream();
}catch (IOException e) {
System.err.println (e);
throw e;
}
output_ = toutput;
// create a single rsvcClient Data Reader and spawn a new thread
reader_ = new rsvcClientReader (this);
readerthread_ = new Thread (reader_);
readerthread_.start ();
}
/**
* Return underlying socket
*/
public Socket getSocket () throws NullPointerException
{
if (tcpsocket_ == null)
throw new NullPointerException ("Socket is invalid");
return tcpsocket_;
}
/**
* Return underlying reader thread
*/
public Thread getReaderThread () throws NullPointerException
{
if (readerthread_ == null)
throw new NullPointerException ("Reader Thread is not alive");
return readerthread_;
}
/**
* Disconnect from the server
*/
public synchronized void disconnect () throws IOException
{
if (tcpsocket_ == null || connected_ == false)
throw new IOException ("Socket is not connected to the server");
try {
tcpsocket_.close();
}catch (IOException e) {
throw e;
}
connected_ = false;
// remove all event handlers
reader_.cleanupEventHandlers ();
}
/**
* Is connection established
*/
public boolean connected ()
{
return connected_;
}
/**
* Register an event handler to handle disconnection event
*/
public synchronized boolean addDisconnectHandler (rsvcEventHandler handler)
{
return reader_.addDisconnectHandler (handler);
}
/**
* Handle server unexpected close
*/
public int handleClose ()
{
try {
tcpsocket_.close ();
} catch (IOException e) {
System.err.println (e);
connected_ = false;
return -1;
}
connected_ = false;
reader_.dispatchDiscEventHandlers ();
// clean up all callbacks
reader_.cleanupEventHandlers ();
return 0;
}
/**
* Create a memory based database with an event handler.
* Data coming back to the event handler contain table definition
*/
public rsvcEvent createMemDbase (String tablename, rsvcData data,
rsvcEventHandler handler) throws IOException
{
rsvcEvent id = null;
data.insert (rsvcConfig.RSVC_TABLE_NAME, tablename);
try {
id = sendCommand (rsvcConfig.RSVC_CREATE_MEMTABLE, data,
handler);
}catch (IOException e) {
throw e;
}
return id;
}
/**
* Open a database with a given name using an event handler.
* Data retured to the event handler contain definition of database
*/
public rsvcEvent openDatabase (String name, rsvcData data,
rsvcEventHandler handler) throws IOException
{
rsvcEvent id = null;
data.insert (rsvcConfig.RSVC_TABLE_NAME, name);
try {
id = sendCommand (rsvcConfig.RSVC_OPEN_DBASE, data,
handler);
}catch (IOException e) {
throw e;
}
return id;
}
/**
* Insert data into a database with a given name.
* The last argument 'overwrite = 1' selects whether to overwite
* existing items in the database.
* Data must match table definition returned from the openDatabase call.
*/
public rsvcEvent insertValue (String name, rsvcData data,
rsvcEventHandler handler,
boolean overwrite) throws IOException
{
rsvcEvent id = null;
data.insert (rsvcConfig.RSVC_TABLE_NAME, name);
if (overwrite == true) {
try {
id = sendCommand (rsvcConfig.RSVC_OVERWRITE, data,
handler);
}catch (IOException e) {
throw e;
}
}
else {
try {
id = sendCommand (rsvcConfig.RSVC_INSERT, data,
handler);
}catch (IOException e) {
throw e;
}
}
return id;
}
/**
* Get data out from the database with a given name.
* Outbound data either contain a tagged value to denote a key value
* such as : "id", "model+gold" or contain multiple tagged values that
* can be constructed into a key value
*/
public rsvcEvent getValue (String name, rsvcData data,
rsvcEventHandler handler) throws IOException
{
rsvcEvent id = null;
data.insert (rsvcConfig.RSVC_TABLE_NAME, name);
try {
id = sendCommand (rsvcConfig.RSVC_GET, data,
handler);
}catch (IOException e) {
throw e;
}
return id;
}
/**
* Delete a data item from the database with a given name.
* Outbound data either contain a tagged value to denote a key value
* such as : "id", "model+gold" or contain multiple tagged values that
* can be constructed into a key value
*/
public rsvcEvent delValue (String name, rsvcData data,
rsvcEventHandler handler) throws IOException
{
rsvcEvent id = null;
data.insert (rsvcConfig.RSVC_TABLE_NAME, name);
try {
id = sendCommand (rsvcConfig.RSVC_DEL, data,
handler);
}catch (IOException e) {
throw e;
}
return id;
}
/**
* Set value for a datum inside database with a given name.
* The outbound data item either contain a tagged value to denote
* a index value e.g.: "id", "model+gold"
* or contains multiple tagged values which can be constructed
* into a key value
* plus a subset of tagged values defined in the table definition
*/
public rsvcEvent setValue (String name, rsvcData data,
rsvcEventHandler handler) throws IOException
{
rsvcEvent id = null;
data.insert (rsvcConfig.RSVC_TABLE_NAME, name);
try {
id = sendCommand (rsvcConfig.RSVC_SET, data,
handler);
}catch (IOException e) {
throw e;
}
return id;
}
/**
* Monitor on a data item inside a database with a given name.
* Any changes to this item will trigger an event coming back.
* The outbound data either contain a tagged value to denote a index value
* Example: "id", "model+gold"
* or contains multiple tagged values which can be constructed
* into a key value.
*/
public rsvcEvent monitorValue (String name, rsvcData data,
rsvcEventHandler handler) throws IOException
{
rsvcEvent id = null;
data.insert (rsvcConfig.RSVC_TABLE_NAME, name);
try {
id = sendMonitor (rsvcConfig.RSVC_MONITOR_ON, data,
handler);
} catch (IOException e) {
throw e;
}
return id;
}
/**
* Monitor off a data inside a database with a given name
* Outbound data either contain a tagged value to denote a index value
* Example: "id", "model+gold"
* or contains multiple tagged values which can be constructed
* into a key value.
*/
public rsvcEvent monitorOffValue (String name, rsvcData data,
rsvcEvent mid) throws IOException
{
rsvcEvent id = null;
data.insert (rsvcConfig.RSVC_TABLE_NAME, name);
try {
id = sendMonitorOff (rsvcConfig.RSVC_MONITOR_OFF, data, mid);
} catch (IOException e) {
throw e;
}
return id;
}
/**
* monitor a single attribute of a data inside a database with a given name.
* any changes to this attribute will trigger an event.
* Data coming back to the event handler containing a whole data.
* Outbound data either contain a tagged value to denote a index value
* Example: "id", "model+gold"
* or contains multiple tagged values which can be constructed
* into a key value
*/
public rsvcEvent monitorAttr (String name, String attr, rsvcData data,
rsvcEventHandler handler) throws IOException
{
rsvcEvent id = null;
data.insert (rsvcConfig.RSVC_TABLE_NAME, name);
data.insert (rsvcConfig.RSVC_MONITOR_TAG, attr);
try {
id = sendMonitor (rsvcConfig.RSVC_MONITOR_ONATTR, data,
handler);
} catch (IOException e) {
throw e;
}
return id;
}
/**
* Stop monitoring a single attribute of a data inside a database.
* Outbound data either contain a tagged value to denote a index value
* Example: "id", "model+gold"
* or contains multiple tagged values which can be constructed
* into a key value .
*/
public rsvcEvent monitorOffAttr (String name, String attr, rsvcData data,
rsvcEvent mid) throws IOException
{
rsvcEvent id = null;
data.insert (rsvcConfig.RSVC_TABLE_NAME, name);
data.insert (rsvcConfig.RSVC_MONITOR_TAG, attr);
try {
id = sendMonitorOff (rsvcConfig.RSVC_MONITOR_OFFATTR, data,
mid);
} catch (IOException e) {
throw e;
}
return id;
}
/**
* query a particular database 'name'
* query msg can be like regular C logic expression for all
* attributes.
*/
public rsvcEvent query (String name, String qmsg,
rsvcEventHandler handler) throws IOException
{
rsvcEvent id = null;
rsvcData data = new rsvcData ();
data.insert (rsvcConfig.RSVC_TABLE_NAME, name);
data.insert (rsvcConfig.RSVC_QUERY_TAG, qmsg);
try {
id = sendCommand (rsvcConfig.RSVC_QUERY, data,
handler);
}catch (IOException e) {
throw e;
}
return id;
}
/**
* Monitor incoming entries inside database
* any insertion to a database will trigger an event
*/
public rsvcEvent monitorIncomingEntries (String name, rsvcData data,
rsvcEventHandler handler) throws IOException
{
rsvcEvent id = null;
data.insert (rsvcConfig.RSVC_TABLE_NAME, name);
try {
id = sendMonitor (rsvcConfig.RSVC_MONITOR_ENTRIES, data,
handler);
} catch (IOException e) {
throw e;
}
return id;
}
/**
* Stop monitoring the incoming entries inside database.
*/
public rsvcEvent monitorOffIncomingEntries (String name, rsvcData data,
rsvcEvent mid) throws IOException
{
rsvcEvent id = null;
data.insert (rsvcConfig.RSVC_TABLE_NAME, name);
try {
id = sendMonitorOff(rsvcConfig.RSVC_MONITOR_OFFENTRIES, data,
mid);
}catch (IOException e) {
throw e;
}
return id;
}
/**
* Generic monitor on command
*/
private synchronized rsvcEvent sendMonitor (int opcode, rsvcData data,
rsvcEventHandler handler) throws IOException
{
int status = rsvcConfig.RSVC_SUCCESS;
// create an event that is being shipped to server
rsvcEvent cbk = new rsvcEvent (data);
cbk.setEventid (eventid_);
cbk.setOpcode (opcode);
// write this event to server
int len = cbk.streamSize ();
// create a buffered data output
BufferedOutputStream boutput = new BufferedOutputStream (output_, len);
try {
cbk.streamOut (boutput);
}catch (IOException e) {
System.err.println (e);
status = rsvcConfig.RSVC_IOFAILED;
throw e;
}
if (status == rsvcConfig.RSVC_SUCCESS) {
try {
boutput.flush ();
}catch (IOException e) {
System.err.println (e);
status = rsvcConfig.RSVC_IOFAILED;
throw e;
}
}
if (status == rsvcConfig.RSVC_SUCCESS) {
cbk.setHandler (handler);
reader_.addMonitorEventHandler (eventid_, cbk);
}
eventid_ ++;
return cbk;
}
/**
* Generic monitor on command
*/
private synchronized rsvcEvent sendMonitorOff (int opcode, rsvcData data,
rsvcEvent monitorEvent) throws IOException
{
int status = rsvcConfig.RSVC_SUCCESS;
if (reader_.containsMonitorEvent (monitorEvent) != true) {
throw new IOException ("Monitor Off using an invalid event");
}
// create new event with differen opcode
rsvcEvent cbk = new rsvcEvent (monitorEvent);
cbk.setOpcode (opcode);
// write this event to server
int len = cbk.streamSize ();
// create a buffered data output
BufferedOutputStream boutput = new BufferedOutputStream (output_, len);
try {
cbk.streamOut (boutput);
}catch (IOException e) {
System.err.println (e);
status = rsvcConfig.RSVC_IOFAILED;
throw e;
}
if (status == rsvcConfig.RSVC_SUCCESS) {
try {
boutput.flush ();
}catch (IOException e) {
System.err.println (e);
status = rsvcConfig.RSVC_IOFAILED;
throw e;
}
}
return cbk;
}
/**
* Generic command call with ith an event handler.
* Data coming back to the event handler contain table definition
*/
private synchronized rsvcEvent sendCommand (int opcode, rsvcData data,
rsvcEventHandler handler) throws IOException
{
int status = rsvcConfig.RSVC_SUCCESS;
// create an event that is being shipped to server
rsvcEvent cbk = new rsvcEvent (data);
cbk.setEventid (eventid_);
cbk.setOpcode (opcode);
// write this event to server
int len = cbk.streamSize ();
// create a buffered data output
BufferedOutputStream boutput = new BufferedOutputStream (output_, len);
try {
cbk.streamOut (boutput);
}catch (IOException e) {
System.err.println (e);
status = rsvcConfig.RSVC_IOFAILED;
throw e;
}
if (status == rsvcConfig.RSVC_SUCCESS) {
try {
boutput.flush ();
}catch (IOException e) {
System.err.println (e);
status = rsvcConfig.RSVC_IOFAILED;
throw e;
}
}
if (status == rsvcConfig.RSVC_SUCCESS) {
cbk.setHandler (handler);
reader_.addCommandEventHandler (eventid_, cbk);
}
eventid_ ++;
return cbk;
}
}

View File

@@ -0,0 +1,315 @@
//-----------------------------------------------------------------------------
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
// Continuous Electron Beam Accelerator Facility
//
// This software was developed under a United States Government license
// described in the NOTICE file included as part of this distribution.
//
// Jefferson Lab HPC Group, 12000 Jefferson Ave., Newport News, VA 23606
//-----------------------------------------------------------------------------
//
// Description:
// rsvcClient Reader that is reading data out of socket
//
// Author:
// Jie Chen
// Jefferson Lab HPC Group
//
// Revision History:
// $Log: rsvcClientReader.java,v $
// Revision 1.1.1.1 2000/05/23 15:12:50 pal
// cdev_psi_1.7.2
//
// Revision 1.2 1999/12/14 15:38:15 chen
// Add scrollbar to display
//
// Revision 1.1 1999/10/18 17:12:39 chen
// *** empty log message ***
//
//
//
//
import java.io.*;
import java.net.*;
import java.util.*;
import rsvcData;
import rsvcEvent;
import rsvcEventHandler;
import rsvcClient;
public final class rsvcClientReader implements Runnable
{
// disconnection callback list (list of event handler)
private Vector discCbkList_ = null;
// all send/get command callback list
private Hashtable cmdCbkList_ = null;
// monitor callback list
private Hashtable monitorCbkTable_ = null;
// Input and output buffer
private DataInputStream input_ = null;
// Pointer back to rsvcClient
private rsvcClient client_;
/**
* Construct a rsvcClientReader from a established client object
*/
public rsvcClientReader (rsvcClient client)
{
client_ = client;
// create lists and a table for event handlers
discCbkList_ = new Vector ();
cmdCbkList_ = new Hashtable (20, (float)0.25);
monitorCbkTable_ = new Hashtable (20, (float)0.25);
InputStream tinput = null;
Socket socket = null;
try {
socket = client_.getSocket();
}catch (NullPointerException e) {
System.err.print (e);
System.exit (-1);
}
try {
tinput = socket.getInputStream();
}catch (IOException e) {
System.err.print (e);
System.exit (-1);
}
input_ = new DataInputStream (tinput);
}
/**
* Add an event handler to handle disconnection event.
* Return true if this event handler is registered successfully.
* Return false if this event handler is already here.
*/
public boolean addDisconnectHandler (rsvcEventHandler handler)
{
if (discCbkList_.contains (handler) == true)
return false;
discCbkList_.addElement (handler);
return true;
}
/**
* Clean up all event handlers
*/
public void cleanupEventHandlers ()
{
discCbkList_.removeAllElements ();
cmdCbkList_.clear ();
monitorCbkTable_.clear ();
}
/**
* Add an event handler to command event handler list
*/
public void addCommandEventHandler (int id,
rsvcEvent oevent)
{
// vector is thread safe
cmdCbkList_.put (new Integer(id), oevent);
}
/**
* Add an event handler to monitor event handler table
*/
public void addMonitorEventHandler (int id, rsvcEvent oevent)
{
// vector is thread safe
monitorCbkTable_.put (new Integer(id), oevent);
}
/**
* Find out whether a particular event is already in the
* monitor event handler table
*/
public boolean containsMonitorEvent (rsvcEvent event)
{
Integer key = new Integer (event.getEventid ());
return monitorCbkTable_.containsKey (key);
}
/**
* Dispatch all event handlers when the server goes down
*/
public void dispatchDiscEventHandlers ()
{
Enumeration list = discCbkList_.elements ();
rsvcEventHandler handler = null;
rsvcEvent event = new rsvcEvent ();
event.setStatus (rsvcConfig.RSVC_DISCONNECTED);
while (list.hasMoreElements ()) {
handler = (rsvcEventHandler)(list.nextElement());
handler.handleEvent (event);
}
}
public void run ()
{
// buffer for header
int headerlen = rsvcEvent.headerLen ();
byte[] header = new byte[headerlen];
ByteArrayInputStream bainput = new ByteArrayInputStream (header);
// buffer for payload
int datasize = 4096;
int prevsize = 4096;
byte[] payload = new byte[datasize];
ByteArrayInputStream plinput = new ByteArrayInputStream (payload);
// event data object
rsvcEvent event = new rsvcEvent ();
while (true) {
// read header
try {
input_.readFully (header);
}catch (IOException e) {
System.err.println ("Server is down");
client_.handleClose ();
break;
}
// reset input stream buffer
bainput.reset ();
try {
datasize = rsvcEvent.readHeader (bainput);
}catch (IOException e) {
System.err.println ("Receiving header error" + e);
client_.handleClose ();
break;
}
if (datasize > prevsize) {
datasize = 2*datasize;
prevsize = datasize;
payload = new byte[datasize];
plinput = new ByteArrayInputStream (payload);
}
// read raw bytes of length 'datasize'
try {
input_.readFully (payload, 0, datasize);
}catch (IOException e) {
System.err.println ("Server is down here");
client_.handleClose ();
break;
}
// convert above raw bytes into an event
plinput.reset ();
try {
event.streamIn (plinput);
}catch (IOException e) {
System.err.println ("Payload data format error: " + e);
client_.handleClose ();
break;
}
// dispatch this event to an appropriate destination
if (dispatchEvent (event) != 0) {
client_.handleClose ();
break;
}
}
System.out.println ("rsvcClientReader Thread is finished");
}
private int dispatchEvent (rsvcEvent event)
{
int op = event.getOpcode ();
int status = 0;
if (op < rsvcConfig.RSVC_MONITOR_ON)
// all simple command transaction events
status = dispatchCmdEventFromServer (event);
else if (op < rsvcConfig.RSVC_OP_UNKNOWN)
// all monitor events
status = dispatchMonitorEventFromServer (event);
else {
System.err.println ("rsvcClient: Invalid option code: " + String.valueOf(op));
status = -1;
}
return status;
}
private int dispatchCmdEventFromServer (rsvcEvent event)
{
Integer key = new Integer (event.getEventid());
int status = event.getStatus ();
Object obj = null;
rsvcEventHandler handler = null;
rsvcEvent oevent = null;
// retrieve object from event which has key value
obj = cmdCbkList_.get (key);
if (obj != null) {
oevent = (rsvcEvent)obj;
if (oevent.match (event) == false) {
System.err.println ("Incoming and outgoing events are not match");
return -1;
}
try {
handler = oevent.getHandler ();
} catch (NullPointerException e) {
System.err.println (e);
return -1;
}
handler.handleEvent (event);
if (status != rsvcConfig.RSVC_INCOMPLETE)
cmdCbkList_.remove (event);
}
else {
System.out.println ("rsvcClient: Event from server does not match");
}
return 0;
}
private int dispatchMonitorEventFromServer (rsvcEvent event)
{
Integer key = new Integer (event.getEventid ());
int status = event.getStatus();
Object obj = null;
rsvcEventHandler handler = null;
rsvcEvent oevent = null;
obj = monitorCbkTable_.get (key);
if (obj != null) {
oevent = (rsvcEvent)obj;
try {
handler = oevent.getHandler ();
}catch (NullPointerException e) {
System.err.println (e);
return -1;
}
handler.handleEvent (event);
if (status != rsvcConfig.RSVC_SUCCESS &&
status != rsvcConfig.RSVC_INCOMPLETE) {
// if an event is bad or finished, remove it
monitorCbkTable_.remove (event);
}
}
else if (status != rsvcConfig.RSVC_SUCCESS) {
System.out.println ("rsvcClient: monitor event from server does not match any");
System.out.println (event.toString());
}
return 0;
}
}

View File

@@ -0,0 +1,110 @@
import java.io.*;
import java.util.*;
import java.net.*;
import rsvcClient;
import rsvcEventHandler;
import rsvcConfig;
public final class rsvcClientTest implements rsvcEventHandler
{
public rsvcClientTest ()
{
// empty
}
public static void main (String[] args)
{
if (args.length < 4) {
System.err.println ("Usage: rsvcClientTest servername domain host port");
System.exit (-1);
}
rsvcClientTest test = new rsvcClientTest ();
String host = args[2];
int port = Integer.valueOf (args[3]).intValue();
String server = args[0];
String domain = args[1];
rsvcClient client = new rsvcClient ();
try {
client.connect (host, port);
}catch (UnknownHostException ue) {
System.err.println (ue);
System.exit (-1);
}catch (IOException e) {
System.err.println (e);
System.exit (-1);
}
// outbound event stream
rsvcEvent oevent = null;
rsvcData serverinfo = new rsvcData ();
serverinfo.insert ("name", server);
serverinfo.insert ("domain", domain);
try {
oevent = client.getValue ("cdevServers", serverinfo,
test);
}catch (IOException e) {
System.err.println (e);
System.exit (-1);
}
try {
oevent = client.query ("cdevServers", "all",
test);
}catch (IOException e) {
System.err.println (e);
System.exit (-1);
}
try {
oevent = client.monitorValue ("cdevServers", serverinfo,
test);
}catch (IOException e) {
System.err.println (e);
System.exit (-1);
}
Thread readerThread = client.getReaderThread ();
try {
readerThread.join ();
} catch (InterruptedException e) {
System.err.println (e);
System.exit (-1);
}
}
public void handleEvent (rsvcEvent event)
{
int status = event.getStatus ();
int opcode = event.getOpcode ();
rsvcData data = event.getData ();
System.out.println ("Handle event is called with status :" + String.valueOf (status));
switch (opcode) {
case rsvcConfig.RSVC_GET:
System.out.println ("Get Value with result :");
break;
case rsvcConfig.RSVC_QUERY:
System.out.println ("Query Value with result :");
break;
default:
System.out.println ("Operation : " + String.valueOf (opcode));
}
if (status == rsvcConfig.RSVC_NOTFOUND)
System.out.println ("Found nothing");
if (status == rsvcConfig.RSVC_SUCCESS)
data.asciiDump ();
}
}

View File

@@ -0,0 +1,169 @@
//-----------------------------------------------------------------------------
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
// Continuous Electron Beam Accelerator Facility
//
// This software was developed under a United States Government license
// described in the NOTICE file included as part of this distribution.
//
// Jefferson Lab HPC Group, 12000 Jefferson Ave., Newport News, VA 23606
//-----------------------------------------------------------------------------
//
// Description:
// RSVC Client Configuration (Must be compatiable to C++ side)
//
// Author:
// Jie Chen
// Jefferson Lab HPC Group
//
// Revision History:
// $Log: rsvcConfig.java,v $
// Revision 1.1.1.1 2000/05/23 15:12:50 pal
// cdev_psi_1.7.2
//
// Revision 1.1 1999/10/18 17:12:40 chen
// *** empty log message ***
//
//
//
public final class rsvcConfig
{
public static final int RSVC_SERVER_PORT = 10932;
public static final int RSVC_MAX_KEY_LEN = 256;
public static final String RSVC_KEY_NAME = "key";
public static final String RSVC_TABLE_NAME = "table";
public static final String RSVC_TABLE_NAME_EXT = ".def";
public static final String RSVC_KEY_TYPE_NAME = "keyType";
public static final String RSVC_KEY_EXP_NAME = "keyExp";
public static final String RSVC_MONITOR_TAG = "monitorOn";
public static final String RSVC_QUERY_TAG = "query";
public static final int RSVC_CACHE_MAX = 20;
public static final int RSVC_CACHE_LF = 5;
public static final int RSVC_RLIMIT_NOFILE = 256;
public static final int RSVC_UDP_BUFFER_SIZE = 4096;
public static final int RSVC_OP_UNKNOWN = 2000;
public static final int RSVC_CREATE_TABLE = 1000;
public static final int RSVC_CREATE_MEMTABLE = 1001;
public static final int RSVC_OPEN_DBASE = 1002;
public static final int RSVC_GET = 1010;
public static final int RSVC_SET = 1011;
public static final int RSVC_DEL = 1012;
public static final int RSVC_INSERT = 1013;
public static final int RSVC_OVERWRITE = 1014;
public static final int RSVC_QUERY = 1020;
public static final int RSVC_MONITOR_ON = 1500;
public static final int RSVC_MONITOR_ONATTR = 1501;
public static final int RSVC_MONITOR_OFF = 1600;
public static final int RSVC_MONITOR_OFFATTR = 1601;
public static final int RSVC_MONITOR_ENTRIES = 1650;
public static final int RSVC_MONITOR_OFFENTRIES = 1651;
public static final int RSVC_SERVER_EXIT = 1700;
public static final int RSVC_DATA_IN_MEMORY = 1;
public static final int RSVC_DATA_ON_DISK = 2;
// database name
public static final String _RSVC_CDEV_SERVERS = "cdevServers";
// key name
public static final String _RSVC_CDEV_SERVERS_KEY = "svcid" ;
// if we do not see a server for 30 seconds, we assume it is dead
public static final int RSVC_CDEV_SERVER_TKO = 30;
// frequency of scanning server database
public static final int RSVC_CDEV_SCAN_PERIOD = 10;
// the following are error status from server
/* Failure of function is non-consequential */
public static final int RSVC_WARNING = -2;
/* Errors that are not in any categories */
public static final int RSVC_ERROR = -1;
/* public static final int RSVC success */
public static final int RSVC_SUCCESS = 0;
/* invalid public static final int RSVC objects */
public static final int RSVC_INVALIDOBJ = 1;
/* invalid argument passed to public static final int RSVC calls */
public static final int RSVC_INVALIDARG = 2;
/* wrong service during dynamic loading */
public static final int RSVC_INVALIDSVC = 3;
/* operation is unsupported (collection) */
public static final int RSVC_INVALIDOP = 4;
/* not connected to low network service */
public static final int RSVC_NOTCONNECTED = 5;
/* low level network service IO failed */
public static final int RSVC_IOFAILED = 6;
/* conflicts of data types or tags */
public static final int RSVC_CONFLICT = 7;
/* public static final int RSVC cannot find user request */
/* (public static final int RSVCData) */
public static final int RSVC_NOTFOUND = 8;
/* time out */
public static final int RSVC_TIMEOUT = 9;
/* public static final int RSVCData conversion error */
public static final int RSVC_CONVERT = 10;
/* value out of range for device attribute */
public static final int RSVC_OUTOFRANGE = 11;
/* insufficient access to perform request */
public static final int RSVC_NOACCESS = 12;
/* change in access permission of device */
public static final int RSVC_ACCESSCHANGED = 13;
/* channel has been disconnected */
public static final int RSVC_DISCONNECTED = 60;
/* channel has been reconnected */
public static final int RSVC_RECONNECTED = 61;
/* overflow existing data buffer */
public static final int RSVC_OVERFLOW = 62;
/* the callback object will be deleted */
public static final int RSVC_DELETE_CALLBACK = 70;
/* data has no key in the data */
public static final int RSVC_NOKEY = 80;
/* connection timeout */
public static final int RSVC_CONN_TIMEOUT = 82;
/* messages have been filtered */
public static final int RSVC_FILTERED = 83;
/* no filtering applied */
public static final int RSVC_NOFILTERING = 84;
/* message is dropped */
public static final int RSVC_DROPPED = 85;
/* TCP io is bad file descriptor */
public static final int RSVC_BADIO = 86;
/* data flow will coming (unfinished) */
public static final int RSVC_INCOMPLETE = 88;
/* callback finished (monitor off) */
public static final int RSVC_CBK_FINISHED = 89;
/* query callback is paused */
public static final int RSVC_PAUSED = 90;
/* query message syntax error */
public static final int RSVC_QUERYMSG_ERR = 91;
/* Request object state values */
/* request object is connected to device */
public static final int RSVC_STATE_CONNECTED = 0;
/* request object is not connected */
public static final int RSVC_STATE_NOTCONNECTED = 1;
/* request object is invalid */
public static final int RSVC_STATE_INVALID = 2;
/* Request object access values */
/* no access to specified attribute */
public static final int RSVC_ACCESS_NONE = 0;
/* read-only access to attribute */
public static final int RSVC_ACCESS_READONLY = 1;
/* read-write access to attribute */
public static final int RSVC_ACCESS_WRITE = 2;
/* public static final int RSVCError class severity codes */
/* informative message */
public static final int RSVC_SEVERITY_INFO = 0;
/* warning message */
public static final int RSVC_SEVERITY_WARN = 1;
/* error message */
public static final int RSVC_SEVERITY_ERROR = 2;
/* severe or fatal error message */
public static final int RSVC_SEVERITY_SEVERE = 3;
public static final int RSVC_IOERROR = 6;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,870 @@
//-----------------------------------------------------------------------------
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
// Continuous Electron Beam Accelerator Facility
//
// This software was developed under a United States Government license
// described in the NOTICE file included as part of this distribution.
//
// Jefferson Lab HPC Group, 12000 Jefferson Ave., Newport News, VA 23606
//-----------------------------------------------------------------------------
//
// Description:
// rsvcDataEntry Class Which is contained inside rsvcData
//
// Author:
// Jie Chen
// Jefferson Lab HPC Group
//
// Revision History:
// $Log: rsvcDataEntry.java,v $
// Revision 1.1.1.1 2000/05/23 15:12:50 pal
// cdev_psi_1.7.2
//
// Revision 1.1 1999/10/18 17:12:40 chen
// *** empty log message ***
//
//
//
//
import java.io.IOException;
import rsvcDataTypes;
import rsvcTimeStamp;
import rsvcDataOutputStream;
public final class rsvcDataEntry
{
private String tag_;
private short type_;
private short ndims_;
private int nelems_;
private Number []data_;
private String []sdata_;
/**
* Construct an empty data entry
*/
public rsvcDataEntry ()
{
tag_ = null;
type_ = rsvcDataTypes.RSVC_INVALID;
ndims_ = -1;
nelems_ = 0;
}
/**
* Construct a tagged data entry from a double value
*/
public rsvcDataEntry (String tag, double d)
{
tag_ = tag;
ndims_ = 0;
nelems_ = 1;
type_ = rsvcDataTypes.RSVC_DOUBLE;
data_ = new Double[1];
data_[0] = new Double (d);
}
/**
* Construct a tagged data entry from a float value
*/
public rsvcDataEntry (String tag, float f)
{
tag_ = tag;
ndims_ = 0;
nelems_ = 1;
type_ = rsvcDataTypes.RSVC_FLOAT;
data_ = new Float[1];
data_[0] = new Float(f);
}
/**
* Construct a tagged data entry from a long value
*/
public rsvcDataEntry (String tag, long l)
{
tag_ = tag;
ndims_ = 0;
nelems_ = 1;
type_ = rsvcDataTypes.RSVC_LONG;
data_ = new Long[1];
data_[0] = new Long(l);
}
/**
* Construct a tagged data entry from an integer value
*/
public rsvcDataEntry (String tag, int i)
{
tag_ = tag;
ndims_ = 0;
nelems_ = 1;
type_ = rsvcDataTypes.RSVC_INT32;
data_ = new Integer[1];
data_[0] = new Integer(i);
}
/**
* Construct a tagged data entry from a short value
*/
public rsvcDataEntry (String tag, short s)
{
tag_ = tag;
ndims_ = 0;
nelems_ = 1;
type_ = rsvcDataTypes.RSVC_INT16;
data_ = new Short[1];
data_[0] = new Short(s);
}
/**
* Construct a tagged data entry from a byte value
*/
public rsvcDataEntry (String tag, byte b)
{
tag_ = tag;
ndims_ = 0;
nelems_ = 1;
type_ = rsvcDataTypes.RSVC_BYTE;
data_ = new Byte[1];
data_[0] = new Byte(b);
}
/**
* Construct a tagged data entry from a string
*/
public rsvcDataEntry (String tag, String str)
{
tag_ = tag;
ndims_ = 0;
nelems_ = 1;
type_ = rsvcDataTypes.RSVC_STRING;
sdata_ = new String[1];
sdata_[0] = str;
}
/**
* Construct a tagged data entry from a time stamp
*/
public rsvcDataEntry (String tag, rsvcTimeStamp ts)
{
tag_ = tag;
ndims_ = 0;
nelems_ = 1;
type_ = rsvcDataTypes.RSVC_TIMESTAMP;
data_ = new rsvcTimeStamp[1];
data_[0] = ts;
}
/**
* Construct a tagged data entry from an array of byte
*/
public rsvcDataEntry (String tag, byte[] barray)
{
tag_ = tag;
ndims_ = 1;
nelems_ = barray.length;
type_ = rsvcDataTypes.RSVC_BYTE;
data_ = new Byte[nelems_];
for (int i = 0; i < nelems_; i++)
data_[i] = new Byte(barray[i]);
}
/**
* Construct a tagged data entry from an array of short
*/
public rsvcDataEntry (String tag, short[] sarray)
{
tag_ = tag;
ndims_ = 1;
nelems_ = sarray.length;
type_ = rsvcDataTypes.RSVC_INT16;
data_ = new Short[nelems_];
for (int i = 0; i < nelems_; i++)
data_[i] = new Short(sarray[i]);
}
/**
* Construct a tagged data entry from an array of integer
*/
public rsvcDataEntry (String tag, int[] iarray)
{
tag_ = tag;
ndims_ = 1;
nelems_ = iarray.length;
type_ = rsvcDataTypes.RSVC_INT32;
data_ = new Integer[nelems_];
for (int i = 0; i < nelems_; i++)
data_[i] = new Integer(iarray[i]);
}
/**
* Construct a tagged data entry from an array of long
*/
public rsvcDataEntry (String tag, long[] larray)
{
tag_ = tag;
ndims_ = 1;
nelems_ = larray.length;
type_ = rsvcDataTypes.RSVC_LONG;
data_ = new Long[nelems_];
for (int i = 0; i < nelems_; i++)
data_[i] = new Long(larray[i]);
}
/**
* Construct a tagged data entry from an array of float
*/
public rsvcDataEntry (String tag, float[] farray)
{
tag_ = tag;
ndims_ = 1;
nelems_ = farray.length;
type_ = rsvcDataTypes.RSVC_FLOAT;
data_ = new Float[nelems_];
for (int i = 0; i < nelems_; i++)
data_[i] = new Float (farray[i]);
}
/**
* Construct a tagged data entry from an array of double
*/
public rsvcDataEntry (String tag, double[] darray)
{
tag_ = tag;
ndims_ = 1;
nelems_ = darray.length;
type_ = rsvcDataTypes.RSVC_DOUBLE;
data_ = new Double[nelems_];
for (int i = 0; i < nelems_; i++)
data_[i] = new Double(darray[i]);
}
/**
* Construct a tagged data entry from an array of strings
*/
public rsvcDataEntry (String tag, String[] strs)
{
tag_ = tag;
ndims_ = 1;
nelems_ = strs.length;
type_ = rsvcDataTypes.RSVC_STRING;
sdata_ = new String[nelems_];
for (int i = 0; i < nelems_; i++)
sdata_[i] = strs[i];
}
/**
* Construct a tagged data entry from an array of time stamps
*/
public rsvcDataEntry (String tag, rsvcTimeStamp[] tsarray)
{
tag_ = tag;
ndims_ = 1;
nelems_ = tsarray.length;
type_ = rsvcDataTypes.RSVC_TIMESTAMP;
data_ = new rsvcTimeStamp[nelems_];
for (int i = 0; i < nelems_; i++)
data_[i] = tsarray[i];
}
/**
* Hash code for this data entry
*/
public int hashCode()
{
return tag_.hashCode();
}
/**
* Compare two data entries
*/
public boolean equals(rsvcDataEntry dobj)
{
if (dobj.type_ != type_ ||
dobj.nelems_ != nelems_ ||
dobj.ndims_ != ndims_ ||
dobj.tag_.equals(tag_) == false)
return false;
int i, j;
if (type_ != rsvcDataTypes.RSVC_INVALID) {
if (type_ == rsvcDataTypes.RSVC_STRING) {
for (i = 0; i < nelems_; i++) {
if (sdata_[i].equals (dobj.sdata_[i]) == false)
return false;
}
}
else {
for (i = 0; i < nelems_; i++) {
if (data_[i].equals (dobj.data_[i]) == false)
return false;
}
}
}
return true;
}
/**
* Retrieve internal data as a byte value
*/
public byte byteValue ()
{
if (type_ != rsvcDataTypes.RSVC_INVALID &&
type_ != rsvcDataTypes.RSVC_STRING)
return data_[0].byteValue();
else if (type_ == rsvcDataTypes.RSVC_STRING)
return Byte.valueOf(sdata_[0]).byteValue();
else throw new NumberFormatException("Uninitialize rsvcDataEntry Object");
}
/**
* Retrieve internal data as a short value
*/
public short shortValue ()
{
if (type_ != rsvcDataTypes.RSVC_INVALID &&
type_ != rsvcDataTypes.RSVC_STRING)
return data_[0].shortValue();
else if (type_ == rsvcDataTypes.RSVC_STRING)
return Short.valueOf(sdata_[0]).shortValue();
else throw new NumberFormatException("Uninitialize rsvcDataEntry Object");
}
/**
* Retrieve internal data as an integer value
*/
public int intValue ()
{
if (type_ != rsvcDataTypes.RSVC_INVALID &&
type_ != rsvcDataTypes.RSVC_STRING)
return data_[0].intValue();
else if (type_ == rsvcDataTypes.RSVC_STRING)
return Integer.valueOf(sdata_[0]).intValue();
else throw new NumberFormatException("Uninitialize rsvcDataEntry Object");
}
/**
* Retrieve internal data as a long value
*/
public long longValue ()
{
if (type_ != rsvcDataTypes.RSVC_INVALID &&
type_ != rsvcDataTypes.RSVC_STRING)
return data_[0].longValue();
else if (type_ == rsvcDataTypes.RSVC_STRING)
return Long.valueOf(sdata_[0]).longValue();
else throw new NumberFormatException("Uninitialize rsvcDataEntry Object");
}
/**
* Retrieve internal data as a float value
*/
public float floatValue ()
{
if (type_ != rsvcDataTypes.RSVC_INVALID &&
type_ != rsvcDataTypes.RSVC_STRING)
return data_[0].floatValue();
else if (type_ == rsvcDataTypes.RSVC_STRING)
return Float.valueOf(sdata_[0]).floatValue();
else throw new NumberFormatException("Uninitialize rsvcDataEntry Object");
}
/**
* Retrieve internal data as a double value
*/
public double doubleValue ()
{
if (type_ != rsvcDataTypes.RSVC_INVALID &&
type_ != rsvcDataTypes.RSVC_STRING)
return data_[0].doubleValue();
else if (type_ == rsvcDataTypes.RSVC_STRING)
return Double.valueOf(sdata_[0]).doubleValue();
else throw new NumberFormatException("Uninitialize rsvcDataEntry Object");
}
/**
* Retrieve internal data as a string
*/
public String stringValue ()
{
if (type_ != rsvcDataTypes.RSVC_INVALID &&
type_ != rsvcDataTypes.RSVC_STRING)
return String.valueOf (data_[0]);
else if (type_ == rsvcDataTypes.RSVC_STRING)
return sdata_[0];
else throw new NumberFormatException("Uninitialize rsvcDataEntry Object");
}
/**
* Retrieve internal data as an array of byte
*/
public byte[] byteArray ()
{
int i;
if (type_ != rsvcDataTypes.RSVC_INVALID &&
type_ != rsvcDataTypes.RSVC_STRING) {
byte[] barray = new byte[nelems_];
for (i = 0; i < nelems_; i++)
barray[i] = data_[i].byteValue();
return barray;
}
else if (type_ == rsvcDataTypes.RSVC_STRING) {
byte[] barray = new byte[nelems_];
for (i = 0; i < nelems_; i++)
barray[i] = Byte.valueOf(sdata_[i]).byteValue();
return barray;
}
else throw new NumberFormatException("Uninitialize rsvcDataEntry Object");
}
/**
* Retrieve internal data as an array of short
*/
public short[] shortArray ()
{
int i;
if (type_ != rsvcDataTypes.RSVC_INVALID &&
type_ != rsvcDataTypes.RSVC_STRING) {
short[] sarray = new short[nelems_];
for (i = 0; i < nelems_; i++)
sarray[i] = data_[i].shortValue();
return sarray;
}
else if (type_ == rsvcDataTypes.RSVC_STRING) {
short[] sarray = new short[nelems_];
for (i = 0; i < nelems_; i++)
sarray[i] = Short.valueOf(sdata_[i]).shortValue();
return sarray;
}
else throw new NumberFormatException("Uninitialize rsvcDataEntry Object");
}
/**
* Retrieve internal data as an array of integer
*/
public int[] intArray ()
{
int i;
if (type_ != rsvcDataTypes.RSVC_INVALID &&
type_ != rsvcDataTypes.RSVC_STRING) {
int[] iarray = new int[nelems_];
for (i = 0; i < nelems_; i++)
iarray[i] = data_[i].intValue();
return iarray;
}
else if (type_ == rsvcDataTypes.RSVC_STRING) {
int[] iarray = new int[nelems_];
for (i = 0; i < nelems_; i++)
iarray[i] = Integer.valueOf(sdata_[i]).intValue();
return iarray;
}
else throw new NumberFormatException("Uninitialize rsvcDataEntry Object");
}
/**
* Retrieve internal data as an array of float
*/
public float[] floatArray ()
{
int i;
if (type_ != rsvcDataTypes.RSVC_INVALID &&
type_ != rsvcDataTypes.RSVC_STRING) {
float[] farray = new float[nelems_];
for (i = 0; i < nelems_; i++)
farray[i] = data_[i].floatValue();
return farray;
}
else if (type_ == rsvcDataTypes.RSVC_STRING) {
float[] farray = new float[nelems_];
for (i = 0; i < nelems_; i++)
farray[i] = Float.valueOf(sdata_[i]).floatValue();
return farray;
}
else throw new NumberFormatException("Uninitialize rsvcDataEntry Object");
}
/**
* Retrieve internal data as an array of double
*/
public double[] doubleArray ()
{
int i;
if (type_ != rsvcDataTypes.RSVC_INVALID &&
type_ != rsvcDataTypes.RSVC_STRING) {
double[] darray = new double[nelems_];
for (i = 0; i < nelems_; i++)
darray[i] = data_[i].doubleValue();
return darray;
}
else if (type_ == rsvcDataTypes.RSVC_STRING) {
double[] darray = new double[nelems_];
for (i = 0; i < nelems_; i++)
darray[i] = Double.valueOf(sdata_[i]).doubleValue();
return darray;
}
else throw new NumberFormatException("Uninitialize rsvcDataEntry Object");
}
/**
* Retrieve internal data as an array of long
*/
public long[] longArray ()
{
int i;
if (type_ != rsvcDataTypes.RSVC_INVALID &&
type_ != rsvcDataTypes.RSVC_STRING) {
long[] larray = new long[nelems_];
for (i = 0; i < nelems_; i++)
larray[i] = data_[i].longValue();
return larray;
}
else if (type_ == rsvcDataTypes.RSVC_STRING) {
long[] larray = new long[nelems_];
for (i = 0; i < nelems_; i++)
larray[i] = Long.valueOf(sdata_[i]).longValue();
return larray;
}
else throw new NumberFormatException("Uninitialize rsvcDataEntry Object");
}
/**
* Retrieve internal data as an array of strings
*/
public String[] stringArray ()
{
int i;
if (type_ != rsvcDataTypes.RSVC_INVALID &&
type_ != rsvcDataTypes.RSVC_STRING) {
String[] sarray = new String[nelems_];
for (i = 0; i < nelems_; i++)
sarray[i] = String.valueOf (data_[i]);
return sarray;
}
else if (type_ == rsvcDataTypes.RSVC_STRING) {
String[] sarray = new String[nelems_];
for (i = 0; i < nelems_; i++)
sarray[i] = sdata_[i];
return sarray;
}
else throw new NumberFormatException("Uninitialize rsvcDataEntry Object");
}
/**
*convert the data entry into a string representation
*/
public String toString ()
{
StringBuffer result = new StringBuffer();
int i, j;
if (type_ == rsvcDataTypes.RSVC_INVALID)
result.append ("Invalid DataEntry Object");
else {
result.append ("Key: ").append (tag_).append ("\n");
result.append ("Type: ").append (rsvcDataTypes.types[type_]).append("\n");
result.append ("NElems: ").append(nelems_).append("\n");
result.append ("Values: \n");
j = 0;
String[] sarray = stringArray();
for (i = 0; i < nelems_; i++) {
if (j == 0)
result.append ("\t");
result.append(sarray[i]).append(" ");
j++;
if (j >= 8) {
result.append ("\n");
j = 0;
}
}
}
return result.toString();
}
/**
* Provide an exact deep copy of this data entry
*/
public rsvcDataEntry copy ()
{
int i;
rsvcDataEntry de = new rsvcDataEntry();
de.type_ = type_;
de.nelems_ = nelems_;
de.ndims_ = ndims_;
if (tag_ != null)
de.tag_ = new String (tag_);
else
de.tag_ = null;
if (type_ != rsvcDataTypes.RSVC_INVALID) {
switch (type_) {
case rsvcDataTypes.RSVC_STRING:
de.sdata_ = new String[nelems_];
for (i = 0; i < nelems_; i++)
de.sdata_[i] = new String(sdata_[i]);
break;
case rsvcDataTypes.RSVC_BYTE:
de.data_ = new Byte[nelems_];
for (i = 0; i < nelems_; i++)
de.data_[i] = new Byte(data_[i].byteValue());
break;
case rsvcDataTypes.RSVC_INT16:
de.data_ = new Short[nelems_];
for (i = 0; i < nelems_; i++)
de.data_[i] = new Short(data_[i].shortValue());
break;
case rsvcDataTypes.RSVC_INT32:
de.data_ = new Integer[nelems_];
for (i = 0; i < nelems_; i++)
de.data_[i] = new Integer(data_[i].intValue());
break;
case rsvcDataTypes.RSVC_FLOAT:
de.data_ = new Float[nelems_];
for (i = 0; i < nelems_; i++)
de.data_[i] = new Float(data_[i].floatValue());
break;
case rsvcDataTypes.RSVC_DOUBLE:
de.data_ = new Double[nelems_];
for (i = 0; i < nelems_; i++)
de.data_[i] = new Double(data_[i].doubleValue());
break;
case rsvcDataTypes.RSVC_LONG:
de.data_ = new Long[nelems_];
for (i = 0; i < nelems_; i++)
de.data_[i] = new Long(data_[i].longValue());
break;
}
}
return de;
}
/**
* Return tag of this data entry
*/
public String getTag ()
{
return tag_;
}
/**
* Set tag to new tag
*/
public void setTag (String tag)
{
tag_ = tag;
}
/**
* Return data type in numeric value
*/
public short getType ()
{
return type_;
}
/**
* Return data type in Class
*/
public Class getClassType () throws ClassNotFoundException
{
if (type_ == rsvcDataTypes.RSVC_INVALID)
throw new ClassNotFoundException ("Invalid data entry object");
else {
if (type_ == rsvcDataTypes.RSVC_STRING)
return sdata_.getClass();
else
return data_.getClass();
}
}
/**
* Return dimensionality information
*/
public short getDimension ()
{
return ndims_;
}
/**
* Return number of elements
*/
public int getNumElements ()
{
return nelems_;
}
/**
* Return streamed data size for this data entry
*/
public int streamSize ()
{
int datasize = 0;
int i;
if (type_ == rsvcDataTypes.RSVC_INVALID)
return datasize;
// size of tag is fixed
datasize += rsvcDataOutputStream.streamSize (tag_,
rsvcDataTypes.RSVC_TAG_MAX_LEN);
// data type, dim, nelems
datasize += 3*rsvcDataOutputStream.streamSize ((int)1);
if (type_ == rsvcDataTypes.RSVC_STRING) {
if (nelems_ == 1)
datasize += rsvcDataOutputStream.streamSize (sdata_[0]);
else {
for (i = 0; i < nelems_; i++)
datasize += rsvcDataOutputStream.streamSize (sdata_[i]);
}
}
else if(type_ == rsvcDataTypes.RSVC_BYTE)
datasize += nelems_*rsvcDataOutputStream.streamSize ((byte)1);
else if(type_ == rsvcDataTypes.RSVC_INT16)
datasize += nelems_*rsvcDataOutputStream.streamSize ((short)1);
else if(type_ == rsvcDataTypes.RSVC_INT32)
datasize += nelems_*rsvcDataOutputStream.streamSize ((int)1);
else if(type_ == rsvcDataTypes.RSVC_FLOAT)
datasize += nelems_*rsvcDataOutputStream.streamSize ((float)1.0);
else if(type_ == rsvcDataTypes.RSVC_DOUBLE)
datasize += nelems_*rsvcDataOutputStream.streamSize ((double)1.0);
else if(type_ == rsvcDataTypes.RSVC_TIMESTAMP){
rsvcTimeStamp ts = new rsvcTimeStamp();
datasize += nelems_*rsvcDataOutputStream.streamSize (ts);
}
else if(type_ == rsvcDataTypes.RSVC_LONG)
datasize += nelems_*rsvcDataOutputStream.streamSize ((long)1);
return datasize;
}
/**
* Convert this data entry into a byte stream
*/
public void streamOut (rsvcDataOutputStream output) throws IOException
{
int i;
if (type_ != rsvcDataTypes.RSVC_INVALID) {
try {
output.write (tag_, rsvcDataTypes.RSVC_TAG_MAX_LEN);
}catch (IOException e) {
throw e;
}
try {
output.write (type_);
}catch (IOException e) {
throw e;
}
try {
output.write (ndims_);
}catch (IOException e) {
throw e;
}
// to make stream data compatible to output generated
// by C++ code
int numelems;
if (type_ == rsvcDataTypes.RSVC_STRING) {
if (ndims_ == 0)
numelems = sdata_[0].length() + 1;
else
numelems = nelems_;
}
else {
if (ndims_ == 0)
numelems = 0;
else
numelems = nelems_;
}
try {
output.write (numelems);
}catch (IOException e) {
throw e;
}
if (type_ == rsvcDataTypes.RSVC_STRING) {
for (i = 0; i < nelems_; i++) {
try {
output.write (sdata_[i]);
}catch (IOException e) {
throw e;
}
}
}
else if (type_ == rsvcDataTypes.RSVC_BYTE) {
for (i = 0; i < nelems_; i++) {
try {
output.write (data_[i].byteValue());
}catch (IOException e) {
throw e;
}
}
}
else if (type_ == rsvcDataTypes.RSVC_INT16) {
for (i = 0; i < nelems_; i++) {
try {
output.write (data_[i].shortValue());
}catch (IOException e) {
throw e;
}
}
}
else if (type_ == rsvcDataTypes.RSVC_INT32) {
for (i = 0; i < nelems_; i++) {
try {
output.write (data_[i].intValue());
}catch (IOException e) {
throw e;
}
}
}
else if (type_ == rsvcDataTypes.RSVC_LONG) {
for (i = 0; i < nelems_; i++) {
try {
output.write (data_[i].longValue());
}catch (IOException e) {
throw e;
}
}
}
else if (type_ == rsvcDataTypes.RSVC_FLOAT) {
for (i = 0; i < nelems_; i++) {
try {
output.write (data_[i].floatValue());
}catch (IOException e) {
throw e;
}
}
}
else if (type_ == rsvcDataTypes.RSVC_DOUBLE) {
for (i = 0; i < nelems_; i++) {
try {
output.write (data_[i].doubleValue());
}catch (IOException e) {
throw e;
}
}
}
else if (type_ == rsvcDataTypes.RSVC_TIMESTAMP) {
for (i = 0; i < nelems_; i++) {
try {
output.write ((rsvcTimeStamp)data_[i]);
}catch (IOException e) {
throw e;
}
}
}
}
}
}

View File

@@ -0,0 +1,240 @@
//-----------------------------------------------------------------------------
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
// Continuous Electron Beam Accelerator Facility
//
// This software was developed under a United States Government license
// described in the NOTICE file included as part of this distribution.
//
// Jefferson Lab HPC Group, 12000 Jefferson Ave., Newport News, VA 23606
//-----------------------------------------------------------------------------
//
// Description:
// rsvcDataInputStream that converts a byte stream into a rsvcData
//
// Author:
// Jie Chen
// Jefferson Lab HPC Group
//
// Revision History:
// $Log: rsvcDataInputStream.java,v $
// Revision 1.1.1.1 2000/05/23 15:12:50 pal
// cdev_psi_1.7.2
//
// Revision 1.1 1999/10/18 17:12:41 chen
// *** empty log message ***
//
//
//
import java.io.*;
import java.math.*;
public class rsvcDataInputStream
{
// for 32 bit machine
public static final int _RSVC_STREAM_BYTE_UNIT = 4;
/**
* Return a long word (32 bit) aligned size from original size
*/
public static final int _RSVC_RNDUP (int x)
{
return ((x + _RSVC_STREAM_BYTE_UNIT - 1)/_RSVC_STREAM_BYTE_UNIT)
* _RSVC_STREAM_BYTE_UNIT;
}
// underlying data output stream
private DataInputStream input = null;
/**
* Construct a data output stream
*/
public rsvcDataInputStream (InputStream stream)
{
try {
input = new DataInputStream (stream);
}catch (Exception e) {
e.printStackTrace();
}
}
/**
* Read a single byte char from stream
*/
public byte readByte () throws IOException
{
int tmp;
try {
tmp = input.readInt ();
}catch (IOException e) {
throw e;
}
return (byte)tmp;
}
/**
* Read a value of short from the stream
*/
public short readShort () throws IOException
{
int tmp;
try {
tmp = input.readInt ();
}catch (IOException e) {
throw e;
}
return (short)tmp;
}
/**
* Read a value of int from stream
*/
public int readInt () throws IOException
{
int tmp;
try {
tmp = input.readInt ();
}catch (IOException e) {
throw e;
}
return tmp;
}
/**
* Read a value of long from stream
*/
public long readLong () throws IOException
{
long tmp;
try {
tmp = input.readLong ();
}catch (IOException e) {
throw e;
}
return tmp;
}
/**
* Read a value of float from stream
*/
public float readFloat () throws IOException
{
float tmp;
try {
tmp = input.readFloat ();
}catch (IOException e) {
throw e;
}
return tmp;
}
/**
* Read a value of double to stream
*/
public double readDouble () throws IOException
{
double tmp;
try {
tmp = input.readDouble ();
}catch (IOException e) {
throw e;
}
return tmp;
}
/**
* Read a string as series of byte using default encoding
*/
public String readString () throws IOException
{
int len, rlen, i;
// first find out str size
try {
len = input.readInt ();
}catch (IOException e) {
throw e;
}
// readout next bytes of strlen
byte[] tmp = new byte[len];
try {
input.readFully (tmp, 0, len);
}catch (IOException e) {
throw e;
}
// find out read length of this string by looking for the first 0
// in this byte array
rlen = 0;
for (i = 0; i < len; i++) {
if (tmp[i] == 0)
break;
}
rlen = i;
return new String (tmp, 0, rlen);
}
/**
* Read a series of byte
*/
public byte[] readBytes () throws IOException
{
int len;
try {
len = input.readInt();
}catch (IOException e){
throw e;
}
byte[] result = new byte[len];
try {
input.readFully (result, 0, len);
}catch (IOException e){
throw e;
}
return result;
}
/**
* Read a number of bytes: blocked until all bytes are read
*/
public byte[] readBytes (int len) throws IOException
{
byte[] result = new byte[len];
try {
input.readFully (result, 0, len);
}catch (IOException e){
throw e;
}
return result;
}
/**
* Read a time stamp from the stream
*/
public rsvcTimeStamp readTimeStamp () throws IOException
{
rsvcTimeStamp ts = new rsvcTimeStamp ();
try {
ts.secPastEpoch = input.readInt();
}catch (IOException e){
throw e;
}
try{
ts.nsec = input.readInt();
}catch (IOException e){
throw e;
}
return ts;
}
}

View File

@@ -0,0 +1,416 @@
//-----------------------------------------------------------------------------
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
// Continuous Electron Beam Accelerator Facility
//
// This software was developed under a United States Government license
// described in the NOTICE file included as part of this distribution.
//
// Jefferson Lab HPC Group, 12000 Jefferson Ave., Newport News, VA 23606
//-----------------------------------------------------------------------------
//
// Description:
// rsvcDataOutputStream that converts a rsvcData into byte stream
//
// Author:
// Jie Chen
// Jefferson Lab HPC Group
//
// Revision History:
// $Log: rsvcDataOutputStream.java,v $
// Revision 1.1.1.1 2000/05/23 15:12:50 pal
// cdev_psi_1.7.2
//
// Revision 1.1 1999/10/18 17:12:41 chen
// *** empty log message ***
//
//
//
import java.io.*;
public class rsvcDataOutputStream
{
// for 32 bit machine
public static final int _RSVC_STREAM_BYTE_UNIT = 4;
/**
* Return a long word (32 bit) aligned size from original size
*/
public static final int _RSVC_RNDUP (int x)
{
return ((x + _RSVC_STREAM_BYTE_UNIT - 1)/_RSVC_STREAM_BYTE_UNIT)
* _RSVC_STREAM_BYTE_UNIT;
}
/**
* Return size information for a single byte
*/
public static int streamSize (byte c)
{
return rsvcDataOutputStream._RSVC_RNDUP ((int)1);
}
/**
* Return size information for a short
*/
public static int streamSize (short c)
{
return rsvcDataOutputStream._RSVC_RNDUP ((int)2);
}
/**
* Return size information for a int
*/
public static int streamSize (int c)
{
return rsvcDataOutputStream._RSVC_RNDUP ((int)4);
}
/**
* Return size information for a long
*/
public static int streamSize (long c)
{
return rsvcDataOutputStream._RSVC_RNDUP ((int)8);
}
/**
* Return size information for a float
*/
public static int streamSize (float c)
{
return rsvcDataOutputStream._RSVC_RNDUP ((int)4);
}
/**
* Return size information for a double
*/
public static int streamSize (double c)
{
return rsvcDataOutputStream._RSVC_RNDUP ((int)8);
}
/**
* Return size information for a string
*/
public static int streamSize (String c)
{
return rsvcDataOutputStream.streamSize ((int)4) +
rsvcDataOutputStream._RSVC_RNDUP ((int)(c.length() + 1));
}
/**
* Return size information for a fix buffer of string
*/
public static int streamSize (String str, int buflen)
{
return rsvcDataOutputStream.streamSize (buflen) +
rsvcDataOutputStream._RSVC_RNDUP(buflen);
}
/**
* Return size information for a double
*/
public static int streamSize (rsvcTimeStamp ts)
{
return 2*rsvcDataOutputStream._RSVC_RNDUP ((int)4);
}
// underlying data output stream
private DataOutputStream out = null;
/**
* Construct a data output stream
*/
public rsvcDataOutputStream (OutputStream stream)
{
try {
out = new DataOutputStream (stream);
}catch (Exception e) {
e.printStackTrace();
}
}
/**
* Return how many bytes have been written to this stream
*/
public final int size ()
{
return out.size ();
}
/**
* Write a single byte char to stream
*/
public void write (char c) throws IOException
{
int tmp = (int)c;
try {
out.writeInt (tmp);
}catch (IOException e) {
throw e;
}
}
/**
* Write a value of short to stream
*/
public void write (short c) throws IOException
{
int tmp = (int)c;
try {
out.writeInt (tmp);
}catch (IOException e) {
throw e;
}
}
/**
* Write a value of int to stream
*/
public void write (int c) throws IOException
{
try {
out.writeInt (c);
}catch (IOException e) {
throw e;
}
}
/**
* Write a value of float to stream
*/
public void write (float c) throws IOException
{
try {
out.writeFloat (c);
}catch (IOException e) {
throw e;
}
}
/**
* Write a value of double to stream
*/
public void write (double c) throws IOException
{
try {
out.writeDouble (c);
}catch (IOException e) {
throw e;
}
}
/**
* Write a value of long to stream
*/
public void write (long c) throws IOException
{
try {
out.writeLong (c);
}catch (IOException e) {
throw e;
}
}
/**
* Write a string as series of byte using default encoding
*/
public void write (String str) throws IOException
{
byte []barray = str.getBytes();
int len = barray.length + 1;
int rlen = rsvcDataOutputStream._RSVC_RNDUP (len);
// first write out how many bytes that follow
try {
out.writeInt (rlen);
}catch (IOException e) {
throw e;
}
// write out string as bytes
try {
out.writeBytes (str);
}catch (IOException e) {
throw e;
}
// write out remainder as 0
for (int i = 0; i < rlen - len + 1; i++) {
try {
out.writeByte (0);
}catch (IOException e) {
throw e;
}
}
}
/**
* Write a string as series of byte using default encoding
* to a maximum length len
*/
public void write (String str, int len) throws IOException
{
if (len % rsvcDataOutputStream._RSVC_STREAM_BYTE_UNIT != 0) {
throw new IOException ("Fix buffer len is not long word aligned");
}
byte []barray = str.getBytes();
if (barray.length >= len) {
// need last 0 for out string buffer
throw new IOException ("Overflow fix buffer");
}
// first write out how many bytes that follow
try {
out.writeInt (len);
}catch (IOException e) {
throw e;
}
// write out string as bytes
try {
out.writeBytes (str);
}catch (IOException e) {
throw e;
}
// write out remainder as 0
for (int i = 0; i < len - barray.length; i++) {
try {
out.writeByte (0);
}catch (IOException e) {
throw e;
}
}
}
/**
* Write a series of byte
*/
public void write (byte[] c) throws Exception
{
if (c == null) throw new NullPointerException();
int len = c.length;
int rlen = rsvcDataOutputStream._RSVC_RNDUP (len);
try {
out.writeInt (rlen);
}catch (IOException e){
throw e;
}
try {
out.write (c, 0, len);
}catch (IOException e){
throw e;
}
for (int i = 0; i < rlen - len; i++) {
try {
out.writeByte (0);
}catch (IOException e){
throw e;
}
}
}
/**
* Write out a time stamp to the stream
*/
public void write (rsvcTimeStamp ts) throws IOException
{
try {
out.writeInt (ts.secPastEpoch);
}catch (IOException e) {
throw e;
}
try {
out.writeInt (ts.nsec);
}catch (IOException e) {
throw e;
}
}
/**
* Write out Byte to the stream
*/
public void write (Byte c) throws IOException
{
try {
write (c.byteValue());
}catch (IOException e) {
throw e;
}
}
/**
* Write out Short to the stream
*/
public void write (Short c) throws IOException
{
try {
write (c.shortValue());
}catch (IOException e) {
throw e;
}
}
/**
* Write out Integer to the stream
*/
public void write (Integer c) throws IOException
{
try {
write (c.intValue());
}catch (IOException e) {
throw e;
}
}
/**
* Write out Float to the stream
*/
public void write (Float c) throws IOException
{
try {
write (c.floatValue());
}catch (IOException e) {
throw e;
}
}
/**
* Write out Double to the stream
*/
public void write (Double c) throws IOException
{
try {
write (c.doubleValue());
}catch (IOException e) {
throw e;
}
}
/**
* Flush data out calling underlying real data stream flush method
*/
public final void flush () throws IOException
{
try {
out.flush ();
}catch (IOException e) {
throw new IOException (e.toString());
}
}
}

View File

@@ -0,0 +1,408 @@
//-----------------------------------------------------------------------------
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
// Continuous Electron Beam Accelerator Facility
//
// This software was developed under a United States Government license
// described in the NOTICE file included as part of this distribution.
//
// Jefferson Lab HPC Group, 12000 Jefferson Ave., Newport News, VA 23606
//-----------------------------------------------------------------------------
//
// Description:
// rsvc data package test
//
// Author:
// Jie Chen
// Jefferson Lab HPC Group
//
// Revision History:
// $Log: rsvcDataTest.java,v $
// Revision 1.1.1.1 2000/05/23 15:12:50 pal
// cdev_psi_1.7.2
//
// Revision 1.1 1999/10/18 17:12:41 chen
// *** empty log message ***
//
//
//
//
import java.io.*;
import rsvcData;
public class rsvcDataTest
{
public static final byte bdata = 1;
public static final short sdata = 2;
public static final int idata = 3;
public static final long ldata = 4;
public static final float fdata = (float)5.0;
public static final double ddata = 6.0;
public static final String strdata = new String ("Hello World I am Here");
public static final String file = new String ("/home/chen/java/rsvc/test.dat");
public static final String coutputfile = new String ("/home/chen/java/rsvc/coutput.dat");
public static final String cinputfile = new String ("/home/chen/java/rsvc/cinput.dat");
static public void integerConvTest ()
{
// test array insert
int []iarray = new int[127];
for (int i = 0; i < 127; i++)
iarray[i] = i;
rsvcData data = new rsvcData ();
data.insert ("value", iarray);
// get data test
rsvcDataEntry de = data.get ("value");
// byte converstion
byte[] ba = de.byteArray ();
rsvcData data1 = new rsvcData ();
data1.insert ("value", ba);
de = data1.get ("value");
int []ia = de.intArray();
rsvcData data2 = new rsvcData();
data2.insert ("value", ia);
if (data.equals (data2))
System.out.print ("Integer -> Byte -> Integer OK\n");
else
System.out.print ("Integer -> Byte -> Integer Failed\n");
// short conversion
de = data.get ("value");
short[] sa = de.shortArray ();
rsvcData data3 = new rsvcData ();
data3.insert ("value", sa);
de = data3.get ("value");
ia = de.intArray ();
rsvcData data4 = new rsvcData();
data4.insert ("value", ia);
if (data.equals (data4))
System.out.print ("Integer -> Short -> Integer OK\n");
else
System.out.print ("Integer -> Short -> Integer Failed\n");
// long conversion
de = data.get ("value");
long[] la = de.longArray ();
rsvcData data5 = new rsvcData ();
data5.insert ("value", la);
de = data5.get ("value");
ia = de.intArray ();
rsvcData data6 = new rsvcData();
data6.insert ("value", ia);
if (data.equals (data6))
System.out.print ("Integer -> Long -> Integer OK\n");
else
System.out.print ("Integer -> Long -> Integer Failed\n");
// float conversion
de = data.get ("value");
float[] fa = de.floatArray ();
rsvcData data7 = new rsvcData ();
data7.insert ("value", fa);
de = data7.get ("value");
ia = de.intArray ();
rsvcData data8 = new rsvcData();
data8.insert ("value", ia);
if (data.equals (data8))
System.out.print ("Integer -> Float -> Integer OK\n");
else
System.out.print ("Integer -> Float -> Integer Failed\n");
// Double conversion
de = data.get ("value");
double[] da = de.doubleArray ();
rsvcData data9 = new rsvcData ();
data9.insert ("value", da);
de = data9.get ("value");
ia = de.intArray ();
rsvcData data10 = new rsvcData();
data10.insert ("value", ia);
if (data.equals (data10))
System.out.print ("Integer -> Double -> Integer OK\n");
else
System.out.print ("Integer -> Double -> Integer Failed\n");
}
static public void floatConvTest ()
{
// test array insert
float []farray = new float[127];
for (int i = 0; i < 127; i++)
farray[i] = (float)i;
rsvcData data = new rsvcData ();
data.insert ("value", farray);
// get data test
rsvcDataEntry de = data.get ("value");
// byte converstion
byte[] ba = de.byteArray ();
rsvcData data1 = new rsvcData ();
data1.insert ("value", ba);
de = data1.get ("value");
float []ia = de.floatArray();
rsvcData data2 = new rsvcData();
data2.insert ("value", ia);
if (data.equals (data2))
System.out.print ("Float -> Byte -> Float OK\n");
else
System.out.print ("Float -> Byte -> Float Failed\n");
// short conversion
de = data.get ("value");
short[] sa = de.shortArray ();
rsvcData data3 = new rsvcData ();
data3.insert ("value", sa);
de = data3.get ("value");
ia = de.floatArray ();
rsvcData data4 = new rsvcData();
data4.insert ("value", ia);
if (data.equals (data4))
System.out.print ("Float -> Short -> Float OK\n");
else
System.out.print ("Float -> Short -> Float Failed\n");
// long conversion
de = data.get ("value");
long[] la = de.longArray ();
rsvcData data5 = new rsvcData ();
data5.insert ("value", la);
de = data5.get ("value");
ia = de.floatArray ();
rsvcData data6 = new rsvcData();
data6.insert ("value", ia);
if (data.equals (data6))
System.out.print ("Float -> Long -> Float OK\n");
else
System.out.print ("Float -> Long -> Float Failed\n");
// Integer conversion
de = data.get ("value");
int[] fa = de.intArray ();
rsvcData data7 = new rsvcData ();
data7.insert ("value", fa);
de = data7.get ("value");
ia = de.floatArray ();
rsvcData data8 = new rsvcData();
data8.insert ("value", ia);
if (data.equals (data8))
System.out.print ("Float -> Integer -> Float OK\n");
else
System.out.print ("Float -> Integer -> Float Failed\n");
// Double conversion
de = data.get ("value");
double[] da = de.doubleArray ();
rsvcData data9 = new rsvcData ();
data9.insert ("value", da);
de = data9.get ("value");
ia = de.floatArray ();
rsvcData data10 = new rsvcData();
data10.insert ("value", ia);
if (data.equals (data10))
System.out.print ("Float -> Double -> Float OK\n");
else
System.out.print ("Float -> Double -> Float Failed\n");
}
public static rsvcData arrayData ()
{
rsvcData data = new rsvcData ();
int i;
// insert array of double
double[] darray = new double[127];
for (i = 0; i < 127; i++)
darray[i] = 123.232 + i*121.121 + i/89.12;
data.insert ("value0", darray);
// insert array of string
String[] sarray = new String[211];
for (i = 0; i < 211; i++)
sarray[i] = new String("value plus " + String.valueOf(i));
data.insert ("value1", sarray);
return data;
}
public static void main (String[] args)
{
rsvcData data = new rsvcData();
// test scaler data insert
data.insert ("value0", bdata);
data.insert ("value1", sdata);
data.insert ("value2", idata);
data.insert ("value3", ldata);
data.insert ("value4", fdata);
data.insert ("value5", ddata);
data.insert ("value6", strdata);
try {
data.dup ("value4", "value3");
}catch (rsvcException e) {
data.remove ("value3");
data.dup ("value4", "value3");
}
data.asciiDump ();
rsvcData data1 = new rsvcData (data);
if (data.equals (data1))
System.out.print ("Data == Data1\n");
else
System.out.print ("Data != Data1\n");
data1.insert ("value0", (byte)12);
if (data.equals (data1))
System.out.print ("Data == Data1\n");
else
System.out.print ("Data != Data1\n");
data1.changeTag ("value2", "value12");
data1.asciiDump ();
rsvcTimeStamp ts = new rsvcTimeStamp();
data1.insert ("value1", ts);
data1.asciiDump ();
integerConvTest ();
floatConvTest();
// test stream out and stream in
File outputfile = new File (rsvcDataTest.file);
FileOutputStream output = null;
try {
output = new FileOutputStream (outputfile);
}catch (IOException e) {
System.out.println (e);
System.exit (-1);
}
// find out how big stream rsvcData will be
// rsvcData olddata = arrayData ();
rsvcData olddata = new rsvcData ();
olddata.insert ("value0", (double)129.01);
olddata.insert ("value1", (double)142323.01);
int dsize = olddata.streamSize ();
System.out.print ("Data size is " + String.valueOf(dsize) + "\n");
// Create Buffered output stream
BufferedOutputStream boutput = new BufferedOutputStream (output, dsize);
try {
olddata.streamOut (boutput);
}catch (IOException e) {
System.out.println (e);
System.exit (-1);
}
try {
boutput.flush();
}catch (IOException e) {
System.out.println (e);
System.exit (-1);
}
// create a buffered input stream
rsvcData newdata = new rsvcData ();
FileInputStream input = null;
try {
input = new FileInputStream (outputfile);
}catch (IOException e) {
System.out.println (e);
System.exit (-1);
}
BufferedInputStream binput = new BufferedInputStream(input, dsize);
try {
newdata.streamIn (binput);
}catch (IOException e) {
System.out.println (e);
System.exit (-1);
}
newdata.asciiDump ();
// test equality between newdata and data
if (olddata.equals (newdata) )
System.out.print ("Data == newdata\n");
else
System.out.print ("Data != newdata\n");
// test whether we can read from a file generated by C code
// create a buffered input stream
rsvcData cdata = new rsvcData ();
try {
input = new FileInputStream (coutputfile);
}catch (IOException e) {
System.out.println (e);
System.exit (-1);
}
binput = new BufferedInputStream(input, 2400);
try {
cdata.streamIn (binput);
}catch (IOException e) {
System.out.println (e);
System.exit (-1);
}
cdata.asciiDump ();
// output some data stream let C++ to pick it up
try {
output = new FileOutputStream (cinputfile);
}catch (IOException e) {
System.out.println (e);
System.exit (-1);
}
boutput = new BufferedOutputStream(output, 2400);
try {
cdata.streamOut (boutput);
}catch (IOException e) {
System.out.println (e);
System.exit (-1);
}
try {
boutput.flush();
}catch (IOException e) {
System.out.println (e);
System.exit (-1);
}
}
}

View File

@@ -0,0 +1,60 @@
//-----------------------------------------------------------------------------
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
// Continuous Electron Beam Accelerator Facility
//
// This software was developed under a United States Government license
// described in the NOTICE file included as part of this distribution.
//
// Jefferson Lab HPC Group, 12000 Jefferson Ave., Newport News, VA 23606
//-----------------------------------------------------------------------------
//
// Description:
// rsvcDataType Class
//
// Author:
// Jie Chen
// Jefferson Lab HPC Group
//
// Revision History:
// $Log: rsvcDataTypes.java,v $
// Revision 1.1.1.1 2000/05/23 15:12:50 pal
// cdev_psi_1.7.2
//
// Revision 1.1 1999/10/18 17:12:42 chen
// *** empty log message ***
//
//
//
//
public final class rsvcDataTypes
{
static public final short RSVC_BYTE = 0;
static public final short RSVC_INT16 = 1;
static public final short RSVC_UINT16 = 2;
static public final short RSVC_INT32 = 3;
static public final short RSVC_UINT32 = 4;
static public final short RSVC_FLOAT = 5;
static public final short RSVC_DOUBLE = 6;
static public final short RSVC_STRING = 7;
static public final short RSVC_TIMESTAMP = 8;
static public final short RSVC_INVALID = 9;
static public final short RSVC_ULONG = 10;
static public final short RSVC_LONG = 11;
static public final short RSVC_TAG_MAX_LEN = 16;
static final String[] types = {"Byte",
"Short",
"Unsigned Short",
"Integer",
"Unsigned Integer",
"Float",
"Double",
"Char String",
"TimeStamp",
"Invalid",
"Unsigned long 64",
"Long 64"
};
}

View File

@@ -0,0 +1,4 @@
<applet name="CDEV Name Server" code=rsvcDisplay width=400 height=100>
<param name=host value=talitha>
<param name=port value=10932>
</applet>

View File

@@ -0,0 +1,592 @@
//-----------------------------------------------------------------------------
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
// Continuous Electron Beam Accelerator Facility
//
// This software was developed under a United States Government license
// described in the NOTICE file included as part of this distribution.
//
// Jefferson Lab HPC Group, 12000 Jefferson Ave., Newport News, VA 23606
//-----------------------------------------------------------------------------
//
// Description:
// JAVA Applet for rsvc name server
//
// Author:
// Jie Chen
// Jefferson Lab HPC Group
//
// Revision History:
// $Log: rsvcDisplay.java,v $
// Revision 1.1.1.1 2000/05/23 15:12:50 pal
// cdev_psi_1.7.2
//
// Revision 1.3 1999/12/14 15:38:16 chen
// Add scrollbar to display
//
// Revision 1.2 1999/10/18 17:16:06 chen
// minor changes
//
// Revision 1.1 1999/10/18 17:12:42 chen
// *** empty log message ***
//
//
//
//
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.net.*;
import rsvcData;
import rsvcDataEntry;
import rsvcClient;
import rsvcEventHandler;
import rsvcConfig;
public class rsvcDisplay extends Applet implements Runnable, rsvcEventHandler
{
// display tag names
private final String[] tags_ = {"name","domain","status","host", "port", "owner"};
private final int numtags_ = 6;
// top level scroll pane
private ScrollPane sclp_ = null;
// top level panel
private Panel dpanel_ = null;
// title field of display
private Label title_ = null;
// information field of display
private Label info_ = null;
// maximum number of entries
private final int size_ = 40;
// current number of entries
private int num_ = 0;
// category filed labels
private Label nameLabel_ = null;
private Label domainLabel_ = null;
private Label statusLabel_ = null;
private Label hostLabel_ = null;
private Label portLabel_ = null;
private Label userLabel_ = null;
// diffrent fields
private TextField[] name_;
private TextField[] domain_;
private TextField[] status_;
private TextField[] host_;
private TextField[] port_;
private TextField[] user_;
// layout
private GridBagLayout layout_ = null;
private GridBagConstraints c_ = null;
// network connection
private rsvcClient client_ = null;
private String serverHost_ = null;
private int serverPort_ = 0;
// seperate thread to handle clean up information box
private Thread timerThread_ = null;
public void setServerHost (String host)
{
serverHost_ = host;
}
public void setServerPort (int p)
{
serverPort_ = p;
}
private void startTimerThread ()
{
if (timerThread_ == null) {
timerThread_ = new Thread (this);
timerThread_.start();
}
else
timerThread_.resume ();
}
private void createLabel (String label)
{
Font lfont = new Font ("times", Font.BOLD, 14);
Color lc = Color.blue;
c_.weightx = 0;
c_.gridwidth = GridBagConstraints.REMAINDER;
title_ = new Label (label, Label.CENTER);
title_.setFont (lfont);
title_.setForeground (lc);
layout_.setConstraints(title_, c_);
dpanel_.add(title_);
}
private void createInfoLabel ()
{
Font lfont = new Font ("times", Font.BOLD, 12);
c_.weightx = 0;
c_.gridwidth = GridBagConstraints.REMAINDER;
info_ = new Label ();
info_.setFont (lfont);
layout_.setConstraints(info_, c_);
dpanel_.add (info_);
}
private void setInformation (String info)
{
info_.setText (info);
}
private void clearInformation ()
{
info_.setText (null);
}
private void createFieldLabels ()
{
Font lfont = new Font ("helvetica", Font.ITALIC, 12);
c_.weightx = 1;
c_.gridwidth = 1;
nameLabel_ = new Label ("Name", Label.CENTER);
nameLabel_.setFont (lfont);
layout_.setConstraints(nameLabel_, c_);
dpanel_.add(nameLabel_);
domainLabel_ = new Label ("Domain", Label.CENTER);
domainLabel_.setFont (lfont);
layout_.setConstraints(domainLabel_, c_);
dpanel_.add(domainLabel_);
statusLabel_ = new Label ("Status", Label.CENTER);
statusLabel_.setFont (lfont);
layout_.setConstraints(statusLabel_, c_);
dpanel_.add(statusLabel_);
c_.gridwidth = 2;
hostLabel_ = new Label ("Host", Label.CENTER);
hostLabel_.setFont (lfont);
layout_.setConstraints(hostLabel_, c_);
dpanel_.add(hostLabel_);
c_.gridwidth = 1;
portLabel_ = new Label ("Port", Label.CENTER);
portLabel_.setFont (lfont);
layout_.setConstraints(portLabel_, c_);
dpanel_.add(portLabel_);
c_.gridwidth = GridBagConstraints.REMAINDER;
userLabel_ = new Label ("User Name", Label.CENTER);
userLabel_.setFont (lfont);
layout_.setConstraints(userLabel_, c_);
dpanel_.add(userLabel_);
}
private void createEmptyFields (int index)
{
c_.gridwidth = 1;
name_[index] = new TextField (10);
name_[index].setEditable (false);
layout_.setConstraints(name_[index], c_);
dpanel_.add(name_[index]);
domain_[index] = new TextField (10);
domain_[index].setEditable (false);
layout_.setConstraints(domain_[index], c_);
dpanel_.add(domain_[index]);
status_[index] = new TextField (10);
status_[index].setEditable (false);
layout_.setConstraints(status_[index], c_);
dpanel_.add(status_[index]);
c_.gridwidth = 2;
host_[index] = new TextField (20);
host_[index].setEditable (false);
layout_.setConstraints(host_[index], c_);
dpanel_.add(host_[index]);
port_[index] = new TextField (10);
port_[index].setEditable (false);
layout_.setConstraints(port_[index], c_);
dpanel_.add(port_[index]);
c_.gridwidth = GridBagConstraints.REMAINDER;
user_[index] = new TextField (10);
user_[index].setEditable (false);
layout_.setConstraints(user_[index], c_);
dpanel_.add(user_[index]);
// force to display
validate ();
}
private void updateEntryAt (rsvcData data, int index)
{
String dispval = null;
int i = 0;
rsvcDataEntry dentry = data.get (tags_[i++]);
dentry = data.get (tags_[i++]);
dentry = data.get (tags_[i++]);
int statusval;
if (dentry != null) {
statusval = dentry.intValue ();
if (statusval == 0) {
status_[index].setBackground (Color.green);
status_[index].setText ("Alive");
}
else if (statusval == 2) {
status_[index].setBackground (Color.red);
status_[index].setText ("Dead");
}
else if (statusval == 1) {
status_[index].setBackground (Color.yellow);
status_[index].setText ("Dormant");
}
else {
status_[index].setBackground (Color.white);
status_[index].setText ("Unknown");
}
}
dentry = data.get (tags_[i++]);
if (dentry != null) {
dispval = dentry.stringValue ();
host_[index].setText (dispval);
}
dentry = data.get (tags_[i++]);
if (dentry != null) {
dispval = dentry.stringValue ();
port_[index].setText (dispval);
}
dentry = data.get (tags_[i++]);
if (dentry != null) {
dispval = dentry.stringValue ();
user_[index].setText (dispval);
}
}
public void updateEntry (rsvcData data, boolean create)
{
int i = 0;
String dispval = null;
String name = null;
String domain = null;
rsvcDataEntry dentry = data.get (tags_[i++]);
if (dentry != null) {
dispval = dentry.stringValue ();
name = dispval;
}
dentry = data.get (tags_[i++]);
if (dentry != null) {
dispval = dentry.stringValue ();
domain = dispval;
}
i = 0;
String tname = null;
String tdomain = null;
int found = 0;
if (name != null && domain != null) {
for (i = 0; i < num_; i++) {
tname = name_[i].getText ();
tdomain = domain_[i].getText ();
if (name.compareTo (tname) == 0 &&
domain.compareTo (tdomain) == 0) {
updateEntryAt (data, i);
found = 1;
break;
}
}
}
if (found == 0 && create == true)
addEntry (data);
}
public void addEntry (rsvcData data)
{
String dispval = null;
int i = 0;
String name = null;
String domain = null;
createEmptyFields (num_);
rsvcDataEntry dentry = data.get (tags_[i++]);
if (dentry != null) {
dispval = dentry.stringValue ();
name_[num_].setText (dispval);
name = dispval;
}
dentry = data.get (tags_[i++]);
if (dentry != null) {
dispval = dentry.stringValue ();
domain_[num_].setText (dispval);
domain = dispval;
}
dentry = data.get (tags_[i++]);
int statusval;
if (dentry != null) {
statusval = dentry.intValue ();
if (statusval == 0) {
status_[num_].setBackground (Color.green);
status_[num_].setText ("Alive");
}
else if (statusval == 2) {
status_[num_].setBackground (Color.red);
status_[num_].setText ("Dead");
}
else if (statusval == 1) {
status_[num_].setBackground (Color.yellow);
status_[num_].setText ("Dormant");
}
else {
status_[num_].setBackground (Color.white);
status_[num_].setText ("Unknown");
}
}
dentry = data.get (tags_[i++]);
if (dentry != null) {
dispval = dentry.stringValue ();
host_[num_].setText (dispval);
}
dentry = data.get (tags_[i++]);
if (dentry != null) {
dispval = dentry.stringValue ();
port_[num_].setText (dispval);
}
dentry = data.get (tags_[i++]);
if (dentry != null) {
dispval = dentry.stringValue ();
user_[num_].setText (dispval);
}
num_ ++;
if (name != null && domain != null) {
rsvcData serverinfo = new rsvcData ();
rsvcEvent oevent = null;
serverinfo.insert ("name", name);
serverinfo.insert ("domain", domain);
try {
oevent = client_.monitorValue ("cdevServers", serverinfo,
this);
}catch (IOException e) {
;
}
}
}
private void cleanupEntries ()
{
for (int i = 0; i < num_; i++) {
remove (name_[i]);
remove (domain_[i]);
remove (status_[i]);
remove (host_[i]);
remove (port_[i]);
remove (user_[i]);
}
num_ = 0;
validate ();
}
public void init ()
{
// create a border layout for applet
setLayout(new BorderLayout ());
// create top level scroll pane
sclp_ = new ScrollPane (ScrollPane.SCROLLBARS_ALWAYS);
add (sclp_);
sclp_.setSize (400, 100);
// create layout manager
layout_ = new GridBagLayout();
c_ = new GridBagConstraints();
c_.fill = GridBagConstraints.BOTH;
// create top level panel
dpanel_ = new Panel (layout_);
dpanel_.setSize (700, 100);
// add this panel to scroll pane
sclp_.add (dpanel_);
// create array of text fields
name_ = new TextField[size_];
domain_ = new TextField[size_];
status_ = new TextField[size_];
host_ = new TextField[size_];
port_ = new TextField[size_];
user_ = new TextField[size_];
num_ = 0;
// create top label
createLabel ("CDEV Name Server Information");
// create information label
createInfoLabel ();
// create category labels
createFieldLabels ();
// create network handler to rsvcServer
client_ = new rsvcClient();
if (serverHost_ == null) {
// get parameters for server host and server port
serverHost_ = getParameter ("host");
serverPort_ = Integer.valueOf (getParameter ("port")).intValue();
}
}
public void start ()
{
// start timer thread
startTimerThread ();
setInformation ("Connecting to server on " + serverHost_ + " at port " + String.valueOf (serverPort_));
try {
client_.connect (serverHost_, serverPort_);
}catch (UnknownHostException ue) {
setInformation ("Unknown Host " + serverHost_);
}catch (IOException e) {
setInformation ("Cannot connect to the server");
}
// if connected
if (client_.connected() == true) {
setInformation ("Connection to the server is established");
// get all
rsvcEvent oevent = null;
try {
oevent = client_.query ("cdevServers", "all", this);
}catch (IOException e) {
setInformation ("Cannot send out query information to the server");
}
// monitor on new entries
rsvcData noused = new rsvcData();
try {
oevent = client_. monitorIncomingEntries ("cdevServers",
noused, this);
} catch (IOException e) {
setInformation ("Cannot send out monitor request to the server");
}
// add disconnection handler
client_.addDisconnectHandler (this);
}
}
public void stop ()
{
if (client_.connected () == true) {
try {
client_.disconnect ();
}catch (IOException e) {
;
}
}
timerThread_.suspend ();
}
public void handleEvent (rsvcEvent event)
{
int status = event.getStatus ();
int opcode = event.getOpcode ();
rsvcData data = event.getData ();
if (status == rsvcConfig.RSVC_DISCONNECTED) {
setInformation ("Server is Gone");
cleanupEntries ();
}
else {
if (opcode == rsvcConfig.RSVC_QUERY) {
if (status == rsvcConfig.RSVC_INCOMPLETE ||
status == rsvcConfig.RSVC_SUCCESS)
addEntry (data);
}
else if (opcode == rsvcConfig.RSVC_MONITOR_ON) {
if (status == rsvcConfig.RSVC_SUCCESS)
updateEntry (data, false);
}
else if (opcode == rsvcConfig.RSVC_MONITOR_ENTRIES) {
if (status == rsvcConfig.RSVC_SUCCESS && data.isEmpty() != true)
updateEntry (data, true);
}
}
}
public void run ()
{
while (true) {
// check to see whether there is something in the
// information display area. If there is, clean out
String infotext = info_.getText ();
if (infotext != null)
info_.setText (null);
// sleep 3 seconds
try {
Thread.sleep (3000);
} catch (InterruptedException e) {
;
}
}
}
public static void main(String args[]) {
if (args.length < 2) {
System.err.println ("Usage: rsvcDisplay host port");
System.exit (-1);
}
Frame f = new Frame("CDEV Name Server Information");
rsvcDisplay display = new rsvcDisplay();
display.setServerHost (args[0]);
display.setServerPort (Integer.valueOf (args[1]).intValue());
display.init();
display.start ();
f.add("Center", display);
f.pack();
f.setSize(f.getPreferredSize());
f.show();
}
}

View File

@@ -0,0 +1,548 @@
//-----------------------------------------------------------------------------
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
// Continuous Electron Beam Accelerator Facility
//
// This software was developed under a United States Government license
// described in the NOTICE file included as part of this distribution.
//
// Jefferson Lab HPC Group, 12000 Jefferson Ave., Newport News, VA 23606
//-----------------------------------------------------------------------------
//
// Description:
// RSVC Server/Client Protocol Information and Data Information
// This class contains protocol information related to callbacks
// 1. operation code
// 2. request id
// 3. socket id -->for server only
// 4. client id
// 5. callback id -->from client to server
//
//
// Author:
// Jie Chen
// Jefferson Lab HPC Group
//
// Revision History:
// $Log: rsvcEvent.java,v $
// Revision 1.1.1.1 2000/05/23 15:12:50 pal
// cdev_psi_1.7.2
//
// Revision 1.1 1999/10/18 17:12:42 chen
// *** empty log message ***
//
//
//
import java.io.*;
import rsvcConfig;
import rsvcData;
import rsvcEventHandler;
public final class rsvcEvent
{
private int opcode_;
private int cbkid_;
private int eventid_;
private int clientid_;
private int socketid_;
private int status_;
private rsvcData data_;
private rsvcEventHandler handler_ = null;
/**
* Construct an emtpy rsvcEvent object
*/
public rsvcEvent ()
{
opcode_ = rsvcConfig.RSVC_OP_UNKNOWN;
cbkid_ = 0;
eventid_ = 0;
clientid_ = 0;
socketid_ = 0;
status_ = rsvcConfig.RSVC_SUCCESS;
data_ = new rsvcData ();
handler_ = null;
}
/**
* Construct a rsvcEvent Object with given parameters
*/
public rsvcEvent (rsvcData data, int opcode, int cbkid)
{
data_ = new rsvcData (data);
opcode_ = opcode;
cbkid_ = cbkid;
eventid_ = 0;
clientid_ = 0;
socketid_ = 0;
status_ = rsvcConfig.RSVC_SUCCESS;
handler_ = null;
}
/**
* Construct a rsvcEvent Object with given parameters
*/
public rsvcEvent (rsvcData data, int opcode, int cbkid,
int eventid, int clientid, int socketid,
int status)
{
data_ = new rsvcData (data);
opcode_ = opcode;
cbkid_ = cbkid;
eventid_ = eventid;
clientid_ = clientid;
socketid_ = socketid;
status_ = status;
handler_ = null;
}
/**
* Construct a rsvcEvent Object without data object
*/
public rsvcEvent (int opcode, int cbkid,
int eventid, int clientid, int socketid,
int status)
{
data_ = new rsvcData();
opcode_ = opcode;
cbkid_ = cbkid;
eventid_ = eventid;
clientid_ = clientid;
socketid_ = socketid;
status_ = status;
handler_ = null;
}
/**
* Construct a rsvcEvent Object with data object only
*/
public rsvcEvent (rsvcData data)
{
data_ = new rsvcData(data);
opcode_ = 0;
cbkid_ = 0;
eventid_ = 0;
clientid_ = 0;
socketid_ = 0;
status_ = rsvcConfig.RSVC_SUCCESS;
handler_ = null;
}
/**
* Construct a rsvcEvent Object using an exising rsvcEvent
*/
public rsvcEvent (rsvcEvent event)
{
data_ = new rsvcData (event.data_);
opcode_ = event.opcode_;
cbkid_ = event.cbkid_;
eventid_ = event.eventid_;
clientid_ = event.clientid_;
socketid_ = event.socketid_;
status_ = event.status_;
handler_ = event.handler_;
}
/**
* Check whether two events have the same signature
*/
public boolean match (rsvcEvent event)
{
if (opcode_ == event.opcode_ &&
cbkid_ == event.cbkid_ &&
eventid_ == event.eventid_)
return true;
return false;
}
/**
* Set data and other paremeters
*/
public void set (rsvcData data,
int opcode, int cbkid,
int eventid, int clientid,
int socketid, int status)
{
data_ = new rsvcData (data);
opcode_ = opcode;
cbkid_ = cbkid;
eventid_ = eventid;
clientid_ = clientid;
socketid_ = socketid;
status_ = status;
}
/**
* Set data and other paremeters
*/
public void set (int opcode, int cbkid,
int eventid, int clientid,
int socketid, int status)
{
opcode_ = opcode;
cbkid_ = cbkid;
eventid_ = eventid;
clientid_ = clientid;
socketid_ = socketid;
status_ = status;
}
/**
* Clean up everything
*/
public void cleanup ()
{
data_.remove ();
cbkid_ = 0;
eventid_ = 0;
clientid_ = 0;
socketid_ = 0;
status_ = rsvcConfig.RSVC_SUCCESS;
handler_ = null;
}
/**
* Get Opcode of this event
*/
public int getOpcode ()
{
return opcode_;
}
/**
* Set opcode of this event
*/
public void setOpcode (int opcode)
{
opcode_ = opcode;
}
/**
* Get request id
*/
public int getEventid ()
{
return eventid_;
}
/**
* Set request id
*/
public void setEventid (int eventid)
{
eventid_ = eventid;
}
/**
* Get client id
*/
public int getClientid ()
{
return clientid_;
}
/**
* Set client id
*/
public void setClientid (int clientid)
{
clientid_ = clientid;
}
/**
* Get cbk id
*/
public int getCbkid ()
{
return cbkid_;
}
/**
* Set cbk id
*/
public void setCbkid (int cbkid)
{
cbkid_ = cbkid;
}
/**
* Get socket id
*/
public int getSocketid ()
{
return socketid_;
}
/**
* Set socket id
*/
public void setSocketid (int socketid)
{
socketid_ = socketid;
}
/**
* Get Status of event
*/
public int getStatus ()
{
return status_;
}
/**
* Set Status Field
*/
public void setStatus (int status)
{
status_ = status;
}
/**
* Get Data Field
*/
public rsvcData getData ()
{
return data_;
}
/**
* Set Data Field
*/
public void setData (rsvcData data)
{
data_ = new rsvcData (data);
}
/**
* Set Handler field
*/
public void setHandler (rsvcEventHandler handler)
{
handler_ = handler;
}
/**
* Get handler field
*/
public rsvcEventHandler getHandler () throws NullPointerException
{
if (handler_ == null) {
throw new NullPointerException ("rsvcEvent has a null handler");
}
return handler_;
}
/**
* Return binary data stream size for this event
*/
public int streamSize ()
{
int dsize = 0;
int size = 0;
// magic number first
dsize += rsvcDataOutputStream.streamSize (rsvcData._RSVC_MAGIC_NUM);
// size of the data to follow after this
dsize += rsvcDataOutputStream.streamSize (size);
// size of 6 integer fields
dsize += 6*rsvcDataOutputStream.streamSize ((int)0);
dsize += data_.streamSize ();
return dsize;
}
/**
* Convert object into a binary data stream
*/
public void streamOut (OutputStream output) throws IOException
{
// calculate total size of this binary stream
int binarysize = streamSize ();
// payload size without magic number and size information
int rsize = binarysize -
rsvcDataOutputStream.streamSize (rsvcData._RSVC_MAGIC_NUM) -
rsvcDataOutputStream.streamSize (binarysize);
rsvcDataOutputStream writer = new rsvcDataOutputStream (output);
// write out magic number first
try{
writer.write (rsvcData._RSVC_MAGIC_NUM);
}catch (IOException e) {
throw e;
}
try {
writer.write (rsize);
}catch (IOException e) {
throw e;
}
// write out six integer field
try {
writer.write (opcode_);
}catch (IOException e) {
throw e;
}
try {
writer.write (cbkid_);
}catch (IOException e) {
throw e;
}
try {
writer.write (eventid_);
}catch (IOException e) {
throw e;
}
try {
writer.write (clientid_);
}catch (IOException e) {
throw e;
}
try {
writer.write (socketid_);
}catch (IOException e) {
throw e;
}
try {
writer.write (status_);
}catch (IOException e) {
throw e;
}
// finally data item itself
try {
data_.streamOut (writer);
}catch (IOException e) {
throw e;
}
}
/**
* Read header information of an incoming stream to find out
* size information of data stream n
*/
public static int readHeader (InputStream stream) throws IOException
{
// attach input stream
rsvcDataInputStream input = new rsvcDataInputStream (stream);
// read magic number first
int magic;
try {
magic = input.readInt ();
}catch (IOException e){
throw e;
}
if (magic != rsvcData._RSVC_MAGIC_NUM) {
throw new IOException ("Magic number mismatch");
}
// get data size
int datasize;
try {
datasize = input.readInt ();
}catch (IOException e) {
throw e;
}
return datasize;
}
/**
* Return streamed event header length
*/
public static int headerLen ()
{
return rsvcDataOutputStream.streamSize (rsvcData._RSVC_MAGIC_NUM) +
rsvcDataOutputStream.streamSize ((int)1);
}
/**
* Convert a stream into an event object
*/
public void streamIn (InputStream stream) throws IOException
{
// clean up this object
cleanup ();
// attach input stream
rsvcDataInputStream input = new rsvcDataInputStream (stream);
try {
opcode_ = input.readInt ();
} catch (IOException e) {
throw e;
}
try {
cbkid_ = input.readInt ();
} catch (IOException e) {
throw e;
}
try {
eventid_ = input.readInt ();
} catch (IOException e) {
throw e;
}
try {
clientid_ = input.readInt ();
} catch (IOException e) {
throw e;
}
try {
socketid_ = input.readInt ();
} catch (IOException e) {
throw e;
}
try {
status_ = input.readInt ();
} catch (IOException e) {
throw e;
}
try {
data_.streamIn (input);
}catch (IOException e) {
throw e;
}
}
public String toString ()
{
StringBuffer result = new StringBuffer ();
result.append ("Event Contains \n");
result.append ("opcode: ").append (opcode_).append ("\n");
result.append ("cbkid: ").append (cbkid_).append ("\n");
result.append ("eventid: ").append (eventid_).append ("\n");
result.append ("clientid: ").append (clientid_).append ("\n");
result.append ("socketid: ").append (socketid_).append ("\n");
result.append ("status: ").append (status_).append ("\n");
result.append (data_.toString());
return result.toString();
}
}

View File

@@ -0,0 +1,34 @@
//-----------------------------------------------------------------------------
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
// Continuous Electron Beam Accelerator Facility
//
// This software was developed under a United States Government license
// described in the NOTICE file included as part of this distribution.
//
// Jefferson Lab HPC Group, 12000 Jefferson Ave., Newport News, VA 23606
//-----------------------------------------------------------------------------
//
// Description:
// RSVC Client Event Handler
//
// Author:
// Jie Chen
// Jefferson Lab HPC Group
//
// Revision History:
// $Log: rsvcEventHandler.java,v $
// Revision 1.1.1.1 2000/05/23 15:12:50 pal
// cdev_psi_1.7.2
//
// Revision 1.1 1999/10/18 17:12:42 chen
// *** empty log message ***
//
//
//
//
public interface rsvcEventHandler
{
public void handleEvent (rsvcEvent event);
}

View File

@@ -0,0 +1,41 @@
//-----------------------------------------------------------------------------
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
// Continuous Electron Beam Accelerator Facility
//
// This software was developed under a United States Government license
// described in the NOTICE file included as part of this distribution.
//
// Jefferson Lab HPC Group, 12000 Jefferson Ave., Newport News, VA 23606
//-----------------------------------------------------------------------------
//
// Description:
// Simple RSVC Package Exception Class
//
// Author:
// Jie Chen
// Jefferson Lab HPC Group
//
// Revision History:
// $Log: rsvcException.java,v $
// Revision 1.1.1.1 2000/05/23 15:12:50 pal
// cdev_psi_1.7.2
//
// Revision 1.1 1999/10/18 17:12:43 chen
// *** empty log message ***
//
//
//
public class rsvcException extends RuntimeException
{
rsvcException ()
{
super ();
}
rsvcException (String s)
{
super (s);
}
}

View File

@@ -0,0 +1,35 @@
//-----------------------------------------------------------------------------
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
// Continuous Electron Beam Accelerator Facility
//
// This software was developed under a United States Government license
// described in the NOTICE file included as part of this distribution.
//
// Jefferson Lab HPC Group, 12000 Jefferson Ave., Newport News, VA 23606
//-----------------------------------------------------------------------------
//
// Description:
// RSVC Net Data (Protocol Part for RSVC Client)
//
// Author:
// Jie Chen
// Jefferson Lab HPC Group
//
// Revision History:
// $Log: rsvcNetData.java,v $
// Revision 1.1.1.1 2000/05/23 15:12:50 pal
// cdev_psi_1.7.2
//
// Revision 1.1 1999/10/18 17:12:43 chen
// *** empty log message ***
//
//
//
//
import rsvcData;
public final class rsvcNetData
{
private rsvcData data_ = null;
private rsvc

View File

@@ -0,0 +1,127 @@
import java.io.*;
import java.util.*;
import java.net.*;
import rsvcClient;
import rsvcEventHandler;
import rsvcConfig;
public final class rsvcServerTest implements rsvcEventHandler
{
public rsvcServerTest ()
{
// empty
}
public static void main (String[] args)
{
if (args.length < 4) {
System.err.println ("Usage: rsvcServerTest name domain host port");
System.exit (-1);
}
rsvcServerTest test = new rsvcServerTest ();
String host = args[2];
int port = Integer.valueOf (args[3]).intValue();
int udpport = port + 1024;
String server = args[0];
String domain = args[1];
rsvcData serverinfo = new rsvcData ();
rsvcData udpinfo = new rsvcData ();
serverinfo.insert ("name", server);
serverinfo.insert ("domain", domain);
serverinfo.insert ("host", host);
serverinfo.insert ("owner", "chen");
serverinfo.insert ("time", (int)(System.currentTimeMillis()/1000));
serverinfo.insert ("port", (int)(System.currentTimeMillis()%65535));
serverinfo.insert ("pid", (int)1234);
udpinfo.insert ("name", server);
udpinfo.insert ("domain", domain);
rsvcClient client = new rsvcClient ();
rsvcUdpClient udpclient = new rsvcUdpClient();
try {
client.connect (host, port);
}catch (UnknownHostException ue) {
System.err.println (ue);
System.exit (-1);
}catch (IOException e) {
System.err.println (e);
System.exit (-1);
}
try {
udpclient.connect (host, udpport);
}catch (UnknownHostException ue) {
System.err.println (ue);
System.exit (-1);
}catch (IOException e) {
System.err.println (e);
System.exit (-1);
}
// outbound event stream
rsvcEvent oevent = null;
try {
oevent = client.insertValue ("cdevServers", serverinfo,
test, true);
}catch (IOException e) {
System.err.println (e);
System.exit (-1);
}
Thread readerThread = client.getReaderThread ();
while (true) {
try {
udpclient.update (udpinfo);
} catch (IOException e) {
System.err.println (e);
System.exit (-1);
}
// wait for 5 seconds
try {
readerThread.join (5000);
} catch (InterruptedException e) {
System.err.println (e);
System.exit (-1);
}
}
}
public void handleEvent (rsvcEvent event)
{
int status = event.getStatus ();
int opcode = event.getOpcode ();
rsvcData data = event.getData ();
System.out.println ("Handle event is called with status :" + String.valueOf (status));
switch (opcode) {
case rsvcConfig.RSVC_GET:
System.out.println ("Get Value with result :");
break;
case rsvcConfig.RSVC_QUERY:
System.out.println ("Query Value with result :");
break;
case rsvcConfig.RSVC_SET:
System.out.println ("Set Value with result :");
break;
default:
System.out.println ("Operation : " + String.valueOf (opcode));
}
if (status == rsvcConfig.RSVC_NOTFOUND)
System.out.println ("Found nothing");
if (status == rsvcConfig.RSVC_SUCCESS)
data.asciiDump ();
}
}

View File

@@ -0,0 +1,114 @@
//-----------------------------------------------------------------------------
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
// Continuous Electron Beam Accelerator Facility
//
// This software was developed under a United States Government license
// described in the NOTICE file included as part of this distribution.
//
// Jefferson Lab HPC Group, 12000 Jefferson Ave., Newport News, VA 23606
//-----------------------------------------------------------------------------
//
// Description:
// Data Type Of Time Stamp
//
// Author:
// Jie Chen
// Jefferson Lab HPC Group
//
// Revision History:
// $Log: rsvcTimeStamp.java,v $
// Revision 1.1.1.1 2000/05/23 15:12:50 pal
// cdev_psi_1.7.2
//
// Revision 1.1 1999/10/18 17:12:44 chen
// *** empty log message ***
//
//
//
import java.util.Date;
public final class rsvcTimeStamp extends Number
{
public int secPastEpoch; // seconds since Jan. 1, 1970
public int nsec; // nano seconds
/**
* Construct a time stamp with current time
*/
public rsvcTimeStamp ()
{
Date d = new Date();
long t = d.getTime();
secPastEpoch = (int)(t/1000);
nsec = (int)(t - secPastEpoch)*1000;
}
/**
* Construct a time stamp with provided second and nano second fields
*/
public rsvcTimeStamp (int sec, int nsec)
{
secPastEpoch = sec + nsec/1000000000;
nsec = nsec - nsec/1000000000 * 1000000000;
}
// all inherited functions
/**
* Return byte value of time stamp
*/
public byte byteValue ()
{
return (byte)secPastEpoch;
}
/**
* Return short value of time stamp
*/
public short shortValue ()
{
return (short)secPastEpoch;
}
/**
* Return integer value of time stamp
*/
public int intValue ()
{
return secPastEpoch;
}
/**
* Return long value of time stamp
*/
public long longValue ()
{
return (long)secPastEpoch;
}
/**
* Return float value of time stamp
*/
public float floatValue ()
{
return (secPastEpoch + nsec/(float)1000000000.0);
}
/**
* Return double value of time stamp
*/
public double doubleValue ()
{
return (secPastEpoch + nsec/1000000000.0);
}
/**
* Return string representation
*/
public String toString ()
{
Date d = new Date ((long)((long)secPastEpoch*1000));
return d.toString();
}
}

View File

@@ -0,0 +1,135 @@
//-----------------------------------------------------------------------------
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
// Continuous Electron Beam Accelerator Facility
//
// This software was developed under a United States Government license
// described in the NOTICE file included as part of this distribution.
//
// Jefferson Lab HPC Group, 12000 Jefferson Ave., Newport News, VA 23606
//-----------------------------------------------------------------------------
//
// Description:
// RSVC UDP Client for Servers to update their time stamps
//
// Author:
// Jie Chen
// Jefferson Lab HPC Group
//
// Revision History:
// $Log: rsvcUdpClient.java,v $
// Revision 1.1.1.1 2000/05/23 15:12:50 pal
// cdev_psi_1.7.2
//
// Revision 1.1 1999/10/18 17:12:44 chen
// *** empty log message ***
//
//
//
import java.io.*;
import java.util.*;
import java.net.*;
import rsvcEvent;
import rsvcData;
import rsvcConfig;
public final class rsvcUdpClient
{
// UDP Socket
private DatagramSocket udpsocket_ = null;
// Destination address for packets
private InetAddress dest_ = null;
// Destination port for packets
private int port_ = 0;
/**
* Construct an empty rsvcUdpClient Object
*/
public rsvcUdpClient ()
{
// empty
}
/**
* Override default finalize method.This allows Java virtual
* machine to clean up resource when this object is no longer
* needed.
*/
protected void finalize() throws Throwable
{
if (udpsocket_ != null)
udpsocket_.close ();
}
/**
* Connect to a server that is on a given host at a given port
*/
public synchronized void connect (String host, int port) throws UnknownHostException, IOException
{
try {
udpsocket_ = new DatagramSocket ();
}catch (IOException e) {
System.err.println(e);
throw e;
}
try {
dest_ = InetAddress.getByName (host);
}catch (UnknownHostException ue) {
throw ue;
}
port_ = port;
}
/**
* A server that is being managed by RSVC sends a very simple data
* to the rsvcServer to manifest itself being alive.
* data is in the form of two tagged ("name", "domain") values or
* anything that will make up an index
*/
public synchronized int update (rsvcData data) throws IOException
{
if (udpsocket_ == null)
return rsvcConfig.RSVC_ERROR;
rsvcEvent cbk = new rsvcEvent (data);
cbk.setOpcode (rsvcConfig.RSVC_SET);
cbk.setEventid (0);
int datasize = cbk.streamSize ();
ByteArrayOutputStream baoutput = new ByteArrayOutputStream (datasize);
try {
cbk.streamOut (baoutput);
}catch (IOException e) {
throw e;
}
// return underlying byte from this byteArrayStream
byte[] obuffer = baoutput.toByteArray ();
if (datasize != obuffer.length) {
throw new IOException ("Streamed out buffer size != original calculated stream size");
}
// construct a datapacket to send data out
DatagramPacket packet = new DatagramPacket (obuffer, datasize,
dest_, port_);
try {
udpsocket_.send (packet);
} catch (IOException e) {
throw e;
}
return rsvcConfig.RSVC_SUCCESS;
}
/**
* Shutdown connection (close socket)
*/
public void disconnect ()
{
if (udpsocket_ != null)
udpsocket_.close ();
}
}