|
||||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | |||||||||
See:
Description
| Interface Summary | |
|---|---|
| CD | CD (ChannelData). |
| CDArray | Interface for an array field. |
| CDArrayArray | CDNonScalarArray - A CRRecord array field that contains non-scalar elements. |
| CDField | CDField - Data for a field of a CDRecord (Channel Data Record) |
| CDGet | Channel put using a CD (Channel Data) to hold the data.. |
| CDGetRequester | The methods implemented by the requester for a CDPut. |
| CDMonitor | Interface for monitoring channel data. |
| CDMonitorRequester | |
| CDPut | Channel put using a CD (Channel Data) to hold the data.. |
| CDPutRequester | The methods implemented by the requester for a CDPut. |
| CDQueue | A queue of CD (ChannelData). |
| CDRecord | CDRecord - A record that holds a PVRecord. |
| CDStructure | CDStructure - A CDRecord field that holds a PVStructure. |
| CDStructureArray | CDNonScalarArray - A CRRecord array field that contains non-scalar elements. |
| Channel | Interface for accessing a channel. |
| ChannelAccess | Interface returned by ChannelAccessFactory. |
| ChannelField | Interface for a field of a channel. |
| ChannelFieldGroup | Interface for getting data from a group of fields. |
| ChannelFieldGroupListener | Listener for field group changes. |
| ChannelGet | Request to get data from a channel. |
| ChannelGetRequester | Requester for a Get.get request. |
| ChannelListener | Listener for connect state changes. |
| ChannelMonitor | Monitor data from a channel. |
| ChannelMonitorNotify | |
| ChannelMonitorNotifyRequester | Requester that monitors a channel without requesting data. |
| ChannelMonitorRequester | Interface |
| ChannelProcess | ChannelProcess - request that a channel be processed.. |
| ChannelProcessRequester | Callback for a channel process request. |
| ChannelProvider | Interface for creating and destroying a channel. |
| ChannelPut | Interface for a channel access put request. |
| ChannelPutGet | Channel access put/get request. |
| ChannelPutGetRequester | Requester for a putGet request. |
| ChannelPutRequester | Requester for ChannelPut requests. |
| Class Summary | |
|---|---|
| AbstractChannel | Abstract class for code that implements Channel. |
| AbstractChannelField | Abstract class for implementing ChannelField. |
| BaseCD | Base class for CD. |
| BaseCDArray | |
| BaseCDArrayArray | Base class for a CD (Channel Data) Array of Arrays. |
| BaseCDField | Implementation of CDField. |
| BaseCDGet | Base class for CD. |
| BaseCDPut | Base class for CD. |
| BaseCDQueue | Base class for a CDQueue. |
| BaseCDRecord | Base class for a CDRecord (Channel Data Record). |
| BaseCDStructure | Base class for a CDStructure (Channel Data Structure). |
| BaseCDStructureArray | Base class for a CD (Channel Data) Array of Structures. |
| BaseChannelFieldGroup | |
| CDFactory | A factory for creating CD and CDQueue. |
| CDMonitorFactory | Factory that implements CDMonitor. |
| ChannelAccessFactory | |
| ChannelMonitorNotifyFactory | |
| ChannelProviderLocalFactory | Factory and implementation of local channel access, i.e. |
| Enum Summary | |
|---|---|
| AccessRights | Access Rights. |
This package contains Java definitions for Channel Access clients
A channel is an interface for acessing data. A channel is implemented by a channelProvider. An arbitrary number of channelProviders are allowed. Each channelProvider has a name and must register itself to ChannelFactory. The underlying data is presented as PVData via a ChannelField. The client can access multiple ChannelFields via a ChannelFieldGroup.
CD (ChannelData) is a facility that, given a ChannelFieldGroup, creates a PVRecord that contains a PVData for each ChannelField as well as a reference to the ChannelField.
A channelProvider must implement the following: Channel, ChannelProvider, ChannelGet, ChannelPut, ChannelPutGet, and ChannelMonitor. All other interfaces, i.e. ChannelMonitorNotify and all the CD interfaces are generic, i.e. implemented by factories provided by the package.
This section defines the interface and factory classes for connecting to a channel and creating interfaces for accessing a channel. The interfaces for accessing a channel are defined in later sections.
A channel is created via a call to ChannelFactory.create(pvName,...). The pvName can optionally consist of three components: 1) A channelName, 2) A fieldName, and 3) options. The details are provider dependent but if possible a provider should support the following syntax:
channelName.fieldName{options}
The channelName is any set of characters not including '.'. The fieldName is all characters after the first '.' up to the optional '{'. If the '{' is present than all characters between the braces are the options. These conventions are supported by the ChannelProviderLocalFactory, which provides access to the local DB database. Other providers may optionally support the same conventions.
For a javaIOC a channelName is a recordName. This is also true for EPICS databases.
interface ChannelListener extends Requester {
void channelStateChange(Channel c,boolean isConnected);
void destroy(Channel c);
}
interface Channel extends Requester {
void connect();
void disconnect();
void destroy();
String getChannelName();
PVRecord getPVRecord();
ChannelListener getChannelListener();
boolean isConnected();
String getPropertyName();
String getFieldName();
String getOptions();
ChannelField createChannelField(String name);
ChannelFieldGroup createFieldGroup(ChannelFieldGroupListener listener);
ChannelProcess createChannelProcess(
ChannelProcessRequester channelProcessRequester);
ChannelGet createChannelGet(ChannelFieldGroup channelFieldGroup,
ChannelGetRequester channelGetRequester,
boolean process);
ChannelPut createChannelPut(ChannelFieldGroup channelFieldGroup,
ChannelPutRequester channelPutRequester,
boolean process);
ChannelPutGet createChannelPutGet(
channelFieldGroup putFieldGroup,ChannelFieldGroup getFieldGroup,
ChannelPutGetRequester channelPutGetRequester,
boolean process);
ChannelMonitor createChannelMonitor(
ChannelMonitorRequester channelMonitorRequester);
boolean add(ChannelProcess channelProcess);
boolean add(ChannelGet channelGet);
boolean add(ChannelPut channelPut);
boolean add(ChannelPutGet channelPutGet);
boolean add(ChannelMonitor channelMonitor);
boolean remove(ChannelProcess channelProcess);
boolean remove(ChannelGet channelGet);
boolean remove(ChannelPut channelPut);
boolean remove(ChannelPutGet channelPutGet);
boolean remove(ChannelMonitor channelMonitor);
}
enum AccessRights {
none,
read,
readWrite
}
interface ChannelField {
Field getField();
PVField getPVField();
void postPut();
ChannelField findProperty(String propertyName);
ChannelField createChannelField(String fieldName);
String[] getPropertyNames();
PVEnumerated getEnumerated();
AccessRights getAccessRights();
}
interface ChannelFieldGroupListener {
void accessRightsChange(Channel channel,ChannelField channelField);
}
interface ChannelFieldGroup {
void addChannelField(ChannelField channelField);
void removeChannelField(ChannelField channelField);
List<ChannelField> getList();
ChannelField[] getArray();
}
interface ChannelMonitorRequester extends Requester{
void beginPut();
void endPut();
void dataPut(PVField modifiedPVField);
void dataPut(PVField requestedPVField,PVField modifiedPVField);
}
interface ChannelMonitor {
void setFieldGroup(ChannelFieldGroup channelFieldGroup);
void getData(CD cd);
void start();
void stop();
void destroy();
}
interface ChannelAccess {
Channel createChannel(String pvName,String[] propertys,
String providerName, ChannelListener listener);
void registerChannelProvider(ChannelProvider channelProvider);
ChannelProvider getChannelProvider(String providerName);
ChannelProvider[] getChannelProviders();
boolean isChannelProvider(String channelName,String providerName);
}
public class ChannelAccessFactory {
static ChannelAccess getChannelAccess();
}
interface ChannelProvider {
Channel createChannel(String pvName,ChannelListener listener);
String getProviderName();
boolean isProvider(String channelName);
void destroy();
}
A channel provides access to an arbitrary number of fields in the record. The methods are:
ChannelListener is an interface that must be implemented by code that creates a channel. It has the methods:
AccessRights is an enum specifying access rights to fields of a channel. Note that access rights are not currently implemented.
ChannelField describes a specific field in a channel.
ChannelFieldGroupListener provides a method that is called whenever the access rights change. The method is:
ChannelFieldGroup has the methods:
ChannelMonitorRequester has the methods:
ChannelMonitor has the methods:
A channelFactory creates a channel. A channel is either local, i.e. code running in an IOC is accessing a field in the local IOC database, or remote, code is accessing a channel that is available over the network. Channelfactory also has methods called by support for local access and by support for remote access.
The methods implemented by ChannelAccess are:
ChannelAccessFactory provides the single method:
This is an interface that must be implemented by code that implements channel access. It is called by ChannelFactory. It has only one method
interface ChannelProcess {
boolean process();
void destroy();
}
interface ChannelProcessRequester extends Requester {
void processDone(RequestResult requestResult);
}
interface ChannelGet {
boolean get();
void getDelayed(PVField pvField);
void destroy();
}
interface ChannelGetRequester extends Requester {
boolean nextGetField(ChannelField field,PVField pvField);
boolean nextDelayedGetField(PVField pvField);
void getDone(RequestResult requestResult);
}
interface ChannelPut {
boolean put();
void putDelayed(PVField pvField);
void destroy();
}
interface ChannelPutRequester extends Requester {
boolean nextPutField(ChannelField field,PVField pvField);
boolean nextDelayedPutField(PVField pvField);
void putDone(RequestResult requestResult);
}
interface ChannelPutGet {
boolean putGet();
void putDelayed(PVField pvField);
void getDelayed(PVField pvField);
void destroy();
}
interface ChannelPutGetRequester extends
ChannelPutRequester,ChannelGetRequester {}
ChannelProcess has the methods:
ChannelProcessRequester has the methods:
A ChannelProcess is created via a call:
ChannelProcess channelProcess = channel.createChannelProcess(this).
The requester must implement interface ChannelProcessRequester. null is returned if the requester is not allowed to process the channel. For example the channel is connected to a record that already has an assigned record processor.
If createChannelProcess or process itself fails, channelProcessRequester.message is called. If process returns true, then channelProcessRequester.requestDone is called when the channel completes processing.
ChannelGet has the methods:
ChannelGetRequester has the methods:
Delayed gets are provided for channel access servers that need to block while handling data. Consider a server that needs to send an array over the network. If it is a very large array, the server has to send the array in multuple network buffers. In order not to lock a database record while the array is being sent it can use the delayed methods. It implements something like:
PVArray pvArray;
int size,offset;
boolean nextGetField(Channel channel,ChannelField field,PVField pvField) {
// recognize that data is actually an array
pvArray = (PVArray)pvField;
size = pvArray.getLength();
offset = 0;
return true;
}
...
while(moreToDo) {
// get networkBuffer. This may block while waiting
channelGet.getDelayed(pvArray();
// send buffer. This might block
if(offset>=size) break; // all done
}
...
boolean nextDelayedGetField(PVField pvField) {
// transfer data to network buffer
// update offset
if(offset<size) return true // getDelayed will again be called
return false // all done
}
ChannelPut has the methods:
ChannelPutRequester has the methods:
Like delayed gets delayed puts are used by servers that need to block. For example servers that transfer data from the network to an IOC database.
This is a combination of ChannelPut and ChannelGet. A typical example is a client request to:
public abstract class AbstractChannel implements Channel{
protected AbstractChannel(ChannelListener channelListener, String options);
protected synchronized void setPVRecord(PVRecord pvRecord,String fieldName);
public synchronized PVRecord getPVRecord();
public synchronized boolean add(ChannelProcess channelProcess);
public synchronized boolean add(ChannelGet channelGet);
public synchronized boolean add(ChannelPut channelPut);
public synchronized boolean add(ChannelPutGet channelPutGet);
public synchronized boolean add(ChannelMonitor channelMonitor);
public synchronized boolean remove(ChannelProcess channelProcess);
public synchronized boolean remove(ChannelGet channelGet);
public synchronized boolean remove(ChannelPut channelPut);
public synchronized boolean remove(ChannelPutGet channelPutGet);
public synchronized boolean remove(ChannelMonitor channelMonitor);
public synchronized String getChannelName();
public String getRequesterName();
public void message(String message, MessageType messageType);
public void connect();
public void disconnect();
public synchronized boolean isConnected();
public void destroy();
public ChannelListener getChannelListener();
public synchronized boolean isConnected();
public synchronized String getFieldName();
public synchronized String getOptions();
public synchronized String getPropertyName();
public synchronized ChannelFieldGroup createFieldGroup(
ChannelFieldGroupListener listener);
}
public class BaseChannelField implements ChannelField { ... }
public class BaseChannelFieldGroup implements ChannelFieldGroup { ... }
AbstractChannel is for use by Channel Providers. The public methods are sufficent for most providers and do not need to be overriden. The provider must call the add and remove methods whenever the corresponding interface is implemented or destroyed. When destroy is called AbstractChannel calls the destroy method of each of the process/get/put/putGet/monitor interfaces.
BaseChannelField implements all ChannelField methods. However the provider must provide a PVField interface to the constructor and often needs to override some of the methods.
BaseChannelFieldGroup implements all ChannelFieldGroup methods. A provider normally can use BaseChannelFieldGroup without overriding any of the methods.
This is support for being notified when a put is issued to a field of an IOC database. The notification does not include data.
public interface ChannelMonitorNotify extends ChannelMonitor{}
interface ChannelMonitorNotifyRequester extends Requester{
void monitorEvent();
}
class ChannelMonitorNotifyFactory {
ChannelMonitorNotify create(Channel channel,
ChannelMonitorNotifyRequester monitorNotifyRequestor);
}
An implementation of a channel access client for accessing records in the IOC database is provided. It has the name "local" This is created automatically by ChannelProviderLocalFactory . The factory creates a single instance of an implementation of a channel access client for accessing local records. ChannelProviderLocalFactory has only one public method.
public class ChannelProviderLocalFactory {
static public void register();
}
This method is called by ChannelFactory when it is called before a local Channel Access is registered.
CD (ChannelData) is a facility that holds a copy of the data contained in a fieldGroup. CD helps solve two problems:
A CD is associated with a channel and channelFieldGroup. When a CD is created via a call to CDFactory.createCD it automatically creates a CDRecord and associated subfields, which are described in the next section.
interface CD {
void destroy();
Channel getChannel();
ChannelFieldGroup getChannelFieldGroup();
CDRecord getCDRecord();
void clearNumPuts();
boolean get(PVField pvField);
boolean put(PVField pvField);
boolean put(PVField pvField,PVField pvSubField);
CDGet createCDGet(
CDGetRequester channelCDGetRequester,
boolean process);
void destroy(CDGet channelCDGet);
CDPut createCDPut(
CDPutRequester cdPutRequester,
boolean process);
void destroy(CDPut cdPut);
}
interface CDQueue {
int getNumberFree();
int capacity();
CD getFree(boolean forceFree);
void setInUse(CD cd);
CD getNext();
int getNumberMissed();
void releaseNext(CD cd);
}
class CDFactory {
static CD createCD(
Channel channel,ChannelFieldGroup channelFieldGroup);
static CDQueue createQueue(
int queueSize,Channel channel,ChannelFieldGroup channelFieldGroup);
}
class BaseCD { ... }
class BaseCDQueue { ... }
class BaseCDPut { ... }
class BaseCDGet { ... }
CD has the following methods:
A CD is allocated as follows:
CD cd = CDFactory.createData(
channel,channelFieldGroup);
This creates storage for each element of the field group. It can create storage for all pvTypes. For Array types, the initial size and capacity is 0. The arrays will grow as data is placed in them but will not be released.
CDQueue has the following methods:
A CDQueue is created as follows:
CDQueue cdQueue = CDFactory.createQueue(
queueSize,channel,channelFieldGroup);
This creates queueSize channelFieldGroups and a queue to manage them. As an example of how a queue is used consider a channel access server monitoring a fieldGroup of an IOC database record.
CDFactory has the following methods:
Each cd provides a set of interfaces for accessing the data values. The data is stored in PVField objects. The complete set of PVFields form a PVRecord, Each CD interface provides access to it's corresponding PV interface. The CD interfaces provide additional methods that allow the client to determine how often each PVField was written.
interface CDField {
CDField getParent();
CDRecord getCDRecord();
ChannelField getChannelField();
PVField getPVField();
int getNumPuts();
void incrementNumPuts();
int getMaxNumPuts();
void setMaxNumPuts(int numPuts);
void clearNumPuts();
void get(PVField pvField,boolean postPut);
void put(PVField pvField);
void put(PVField pvField,PVField pvSubField);
String toString();
String toString(int indentLevel);
}
interface CDRecord {
CDField findCDField(PVField pvField);
CDField findSourceCDField(PVField sourcePVField);
PVRecord getPVRecord();
CDStructure getCDStructure();
PVDataCreate getPVDataCreate();
}
interface CDStructure extends CDField {
CDField findCDField(PVField pvField);
CDField findSourceCDField(PVField sourcePVField);
CDField[] getCDFields();
PVStructure getPVStructure();
}
interface CDArray extends CDField{
PVArray getPVArray();
}
interface CDArrayArray extends CDArray {
CDField findCDField(PVField pvField);
CDField findSourceCDField(PVField sourcePVField);
CDArray[] getElementCDArrays();
}
interface CDStructureArray extends CDArray {
CDField findCDField(PVField pvField);
CDField findSourceCDField(PVField sourcePVField);
CDStructure[] getElementCDStructures();
}
class BaseCDRecord { ... }
class BaseCDField { ... }
class BaseCDArray { ... }
class BaseCDStructure { ... }
class BaseCDStructureArray { ... }
class BaseCDArrayArray { ... }
Each field in the PVRecord associated with CDRecord has an associated CDField or an extension. CDField has the methods:
CDRecord is for the ChannelFieldGroup. It has the methods:
CDStructure is associated with a PVStructure. It has the methods:
CDArray is associated with a PVArray. It has the method:
CDArray is associated with a PVArray. It has the method:
CDStructureArray is associated with a PVArray with structure elements.
CDArrayArray is associated with a PVArray with array elements.
The BaseCD classes provide implementations of the CD interraces. These provide complete imnplementations and should rarely need to be extended.
public interface CDGet {
void destroy();
void get(CD cd);
}
public interface CDGetRequester extends Requester{
void getDone(RequestResult requestResult);
}
CDGet has the methods:
CDGetRequester has the methods:
interface CDPut {
void destroy();
void get(CD cd);
void put(CD cd);
}
public interface CDPutRequester extends Requester{
void getDone();
void putDone(RequestResult requestResult);
}
This is a put that uses a CD to hold the data. The caller puts data into the CD before calling CDPut.put().
CDPut has the methods:
CDPutRequester has the methods:
This is support for being notified when a put is issued to a field of an IOC database. The notification includes data.
interface CDMonitor {
void lookForPut(ChannelField channelField, boolean causeMonitor);
void lookForChange(ChannelField channelField, boolean causeMonitor);
void lookForAbsoluteChange(ChannelField channelField,double value);
void lookForPercentageChange(ChannelField channelField,double value);
void start(int queueSize,IOCExecutor iocExecutor);
void stop();
}
interface CDMonitorRequester extends Requester{
void monitorCD(CD cD);
void dataOverrun(int number);
}
class CDMonitorFactory {
public static CDMonitor create(Channel channel,
CDMonitorRequester cdMonitorRequester)
}
CDMonitor has the methods:
CDMonitorRequester has the methods:
CDMonitorRequester has the method:
This example creates a CD for a fieldGroup that has the following:
The definition is:
static class ValueData implements ChannelFieldGroupListener{
ValueData(Channel channel);
ChannelFieldGroup init();
void clear();
boolean nextGetField(Channel channel, ChannelField field, PVField pvField);
void printResults();
}
where
What it provides for later examples is the ability to dump everthing an example gets from a record after the record is no longer locked.
class ValueData implements ChannelFieldGroupListener{
private Channel channel;
private String fieldName;
private ChannelFieldGroup channelFieldGroup;
private ChannelField valueField;
private ChannelField alarmField = null;
private ChannelField timeStampField = null;
ValueData(Channel channel,String fieldName) {
this.channel = channel;
this.fieldName = fieldName;
}
public void accessRightsChange(Channel channel, ChannelField channelField) {
// TODO Auto-generated method stub
}
private ChannelFieldGroup init() {
channelFieldGroup = channel.createFieldGroup(this);
valueField = channel.createChannelField(fieldName);
if(valueField==null) {
System.out.printf("findField returned %s%n", result.toString());
return null;
}
channelFieldGroup.addChannelField(valueField);
alarmField = valueField.findProperty("alarm");
if(alarmField!=null) channelFieldGroup.addChannelField(alarmField);
timeStampField = valueField.findProperty("timeStamp");
if(timeStampField!=null) channelFieldGroup.addChannelField(timeStampField);
return channelFieldGroup;
}
private String printResults(CD cd) {
StringBuilder builder = new StringBuilder();
ChannelFieldGroup channelFieldGroup = cd.getChannelFieldGroup();
List<ChannelField> channelFieldList = channelFieldGroup.getList();
CDStructure cdStructure = cd.getCDRecord().getCDStructure();
CDField[] cdbDatas = cdStructure.getCDFields();
int maxNumPuts = cd.getMaxPutsToField();
if(maxNumPuts!=1) {
builder.append(String.format(
" maxNumPuts %d ",maxNumPuts));
}
for(int i=0;i<cdbDatas.length; i++) {
CDField cdField = cdbDatas[i];
maxNumPuts = cdField.getMaxNumPuts();
if(maxNumPuts<=0) continue;
if(maxNumPuts!=1) {
builder.append(String.format(
" maxNumPuts %d ",maxNumPuts));
}
PVField pvField = cdField.getPVField();
ChannelField channelField = channelFieldList.get(i);
if(channelField==valueField) {
builder.append(String.format(
"value %s ",
pvField.toString(2)));
} else if(channelField==alarmField) {
builder.append(String.format(" alarm %s",
pvField.toString()));
} else if(channelField==timeStampField) {
PVTimeStamp pvTimeStamp = PVTimeStamp.create(pvField);
TimeStamp timeStamp = new TimeStamp();
pvTimeStamp.get(timeStamp);
long seconds = timeStamp.secondsPastEpoch;
int nano = timeStamp.nanoSeconds;
long now = nano/1000000 + seconds*1000;
Date date = new Date(now);
builder.append(String.format(" time %s",
date.toLocaleString()));
}
if(cdField.getNumSupportNamePuts()>0) {
builder.append(String.format("supportName %s numSupportNamePuts %d%n",
pvField.getSupportName(),cdField.getNumSupportNamePuts()));
}
}
return builder.toString();
}
}
This example shows how to implement a process request.
static class Process implements ChannelProcessRequester,ChannelListener
{
private Lock lock = new ReentrantLock();
private Condition waitDone = lock.newCondition();
private boolean allDone = false;
private String pvname = null;
private Channel channel;
private ChannelProcess channelProcess;
Process(String pvname) {
this.pvname = pvname;
channel = ChannelFactory.createChannel(pvname, this);
channelProcess = channel.createChannelProcess(this);
// SHOULD CHECK FOR NULL
}
void destroy() {
channel.destroy();
}
void process() {
allDone = false;
channelProcess.process();
lock.lock();
try {
if(!allDone) {
waitDone.await();
}
} catch (InterruptedException e) {
return;
} finally {
lock.unlock();
}
}
public String getRequesterName() {
return "Put:" + pvname;
}
public void message(String message, MessageType messageType) {
message(channel,message,messageType);
}
public void message(Channel channel, String message, MessageType messageType) {
System.out.printf("putGet.massage %s%n", message);
}
public void requestDone(Channel channel, RequestResult requestResult) {
lock.lock();
try {
allDone = true;
waitDone.signal();
} finally {
lock.unlock();
}
}
public void channelStateChange(Channel c, boolean isConnected) { }
public void disconnect(Channel c) { }
public void accessRightsChange(Channel channel, ChannelField channelField) { }
}
This example shows how to implement a get request.
static class Get implements
ChannelGetRequester,
ChannelListener, ChannelFieldGroupListener
{
private Lock lock = new ReentrantLock();
private Condition waitDone = lock.newCondition();
private boolean allDone = false;
private String pvname = null;
private Channel channel;
private ChannelGet channelGet;
private ValueData valueData;
private ChannelFieldGroup getFieldGroup;
Get(String pvname,boolean process) {
this.pvname = pvname;
channel = ChannelFactory.createChannel(pvname, this);
channelGet = channel.createChannelGet(this, process);
}
void destroy() {
channel.destroy();
}
boolean connect() {
valueData = new ValueData(channel);
getFieldGroup = valueData.init();
if(getFieldGroup==null) return false;
return true;
}
void get() {
allDone = false;
valueData.clear();
channelGet.get(getFieldGroup);
lock.lock();
try {
if(!allDone) {
waitDone.await();
}
} catch (InterruptedException ie) {
return;
} finally {
lock.unlock();
}
valueData.printResults();
}
public boolean nextDelayedGetField(PVField pvField) {
//nothing to do
}
public String getRequesterName() {
return "PutGet:" + pvname;
}
public void message(String message, MessageType messageType) {
message(channel,message,messageType);
}
public boolean nextGetField(Channel channel, ChannelField field, PVField pvField) {
valueData.nextGetField(channel, field, pvField);
return false;
}
public void message(Channel channel, String message, MessageType messageType) {
System.out.printf("putGet.massage %s%n", message);
}
public void requestDone(Channel channel, RequestResult requestResult) {
lock.lock();
try {
allDone = true;
waitDone.signal();
} finally {
lock.unlock();
}
}
public void channelStateChange(Channel c, boolean isConnected) { }
public void disconnect(Channel c) { }
public void accessRightsChange(Channel channel, ChannelField channelField) { }
}
This example shows how to implement a put request.
static class Put implements
ChannelPutRequester,
ChannelListener, ChannelFieldGroupListener
{
private Lock lock = new ReentrantLock();
private Condition waitDone = lock.newCondition();
private boolean allDone = false;
private String pvname = null;
private Channel channel;
private ChannelPut channelPut;
private ChannelFieldGroup putFieldGroup;
private ChannelField valueField;
private double value;
Put(String pvname, boolean process) {
this.pvname = pvname;
channel = ChannelFactory.createChannel(pvname, this);
channelPut = channel.createChannelPut(this, process);
}
public boolean nextDelayedPutField(PVField pvField) {
// nothing to do
return false;
}
void destroy() {
channel.destroy();
}
boolean connect() {
putFieldGroup = channel.createFieldGroup(this);
valueField = channel.findField("value");
if(valueField==null) {
System.out.println("PutGet:set value not found");
return false;
}
putFieldGroup.addChannelField(valueField);
return true;
}
void put(double value) {
this.value = value;
allDone = false;
channelPut.put(putFieldGroup);
lock.lock();
try {
if(!allDone) {
waitDone.await();
}
} catch (InterruptedException ie) {
return;
} finally {
lock.unlock();
}
}
public String getRequesterName() {
return "Put:" + pvname;
}
public void message(String message, MessageType messageType) {
message(channel,message,messageType);
}
public boolean nextPutField(Channel channel, ChannelField field, PVField pvField) {
PVDouble pvDouble = (PVDouble)pvField;
pvDouble.put(value);
return false;
}
public void message(Channel channel, String message, MessageType messageType) {
System.out.printf("putGet.massage %s%n", message);
}
public void requestDone(Channel channel, RequestResult requestResult) {
lock.lock();
try {
allDone = true;
waitDone.signal();
} finally {
lock.unlock();
}
}
public void channelStateChange(Channel c, boolean isConnected) { }
public void disconnect(Channel c) { }
public void accessRightsChange(Channel channel, ChannelField channelField) { }
}
This example shows how to implement a putGet request. When the put method is called, it puts a double value to a field named value, optionally processes the record, and retrieves the value, status, severity, and timeStamp.
static class PutGet implements
ChannelPutGetRequester,
ChannelListener, ChannelFieldGroupListener
{
private Lock lock = new ReentrantLock();
private Condition waitDone = lock.newCondition();
private boolean allDone = false;
private String pvname = null;
private Channel channel;
private ChannelPutGet channelPutGet;
private ChannelFieldGroup putFieldGroup;
private ValueData valueData;
private ChannelFieldGroup getFieldGroup;
private ChannelField valueField;
private double value;
PutGet(String pvname,boolean process) {
this.pvname = pvname;
channel = ChannelFactory.createChannel(pvname, this);
channelPutGet = channel.createChannelPutGet(this, process);
}
public boolean nextDelayedPutField(PVField pvField) {
// Nothing to do
return false;
}
public boolean nextDelayedGetField(PVField pvField) {
// Nothing to do
return false;
}
boolean connect() {
putFieldGroup = channel.createFieldGroup(this);
valueField = channel.findField("value");
if(valueField==null) {
System.out.println("PutGet:set value not found");
return false;
}
putFieldGroup.addChannelField(valueField);
valueData = new ValueData(channel);
getFieldGroup = valueData.init();
if(getFieldGroup==null) return false;
return true;
}
void destroy() {
channel.destroy();
}
void putGet(double value) {
this.value = value;
allDone = false;
valueData.clear();
channelPutGet.putGet(putFieldGroup, getFieldGroup);
lock.lock();
try {
if(!allDone) {
waitDone.await();
}
} catch (InterruptedException ie) {
return;
} finally {
lock.unlock();
}
valueData.printResults();
}
public String getRequesterName() {
return "PutGet:" + pvname;
}
public void message(String message, MessageType messageType) {
message(channel,message,messageType);
}
public boolean nextGetField(Channel channel, ChannelField field, PVField pvField) {
valueData.nextGetField(channel, field, pvField);
return false;
}
public boolean nextPutField(Channel channel, ChannelField field, PVField pvField) {
PVDouble pvDouble = (PVDouble)pvField;
pvDouble.put(value);
return false;
}
public void message(Channel channel, String message, MessageType messageType) {
System.out.printf("putGet.massage %s%n", message);
}
public void requestDone(Channel channel, RequestResult requestResult) {
lock.lock();
try {
allDone = true;
waitDone.signal();
} finally {
lock.unlock();
}
}
public void channelStateChange(Channel c, boolean isConnected) { }
public void disconnect(Channel c) { }
public void accessRightsChange(Channel channel, ChannelField channelField) { }
}
|
||||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | |||||||||