@Override public synchronized Map<String, Object> getProperties() { Map<String, Object> properties = new HashMap<String, Object>(); if (channel != null) { properties.put("Channel name", channel.getChannelName()); properties.put("Connection state", channel.getConnectionState().name()); properties.put("Provider name", channel.getProvider().getProviderName()); if (channel.getConnectionState() == Channel.ConnectionState.CONNECTED) { properties.put("Remote address", channel.getRemoteAddress()); properties.put("Channel type", channelType.getID()); // properties.put("Read access", channel.getReadAccess()); // properties.put("Write access", channel.getWriteAccess()); } } return properties; }
@Override public void addReader(ChannelHandlerReadSubscription subscription) { super.addReader(subscription); if (!monitorCreated.getAndSet(true)) { // TODO remove this.... for (int i = 0; i < 100 && channel.getConnectionState() == ConnectionState.NEVER_CONNECTED; i++) { try { Thread.sleep(100); } catch (InterruptedException e) { } } // TODO optimize fields channel.createMonitor(this, CreateRequestFactory.createRequest("field()", this)); } }
@Override public void write(Object newValue, ChannelWriteCallback callback) { boolean wasEmpty; synchronized (writeRequests) { wasEmpty = writeRequests.isEmpty(); writeRequests.add(new WriteRequest(newValue, callback)); } if (!channelPutCreated.getAndSet(true)) { channel.createChannelPut(this, isChannelEnumType ? enumPutPVRequest : standardPutPVRequest); } else if (wasEmpty) { doNextWrite(); } }
@Override public void channelStateChange(Channel channel, ConnectionState connectionState) { try { // introspect if (connectionState == ConnectionState.CONNECTED) { channel.getField(this, null); } else { processConnection(this); } } catch (Exception ex) { reportExceptionToAllReadersAndWriters(ex); } }
/* (non-Javadoc) * @see org.epics.pvaccess.client.GetFieldRequester#getDone(org.epics.pvdata.pv.Status, org.epics.pvdata.pv.Field) */ @Override public void getDone(Status status, Field field) { reportStatus("Failed to instrospect channel '" + channel.getChannelName() + "'", status); if (status.isSuccess()) { channelType = field; Field valueField = ((Structure) channelType).getField("value"); if (valueField != null && valueField.getID().equals("enum_t")) { isChannelEnumType = true; // TODO could create a monitor just to get value.choices } else isChannelEnumType = false; } processConnection(this); }
@Override public void disconnect() { // Close the channel try { channel.destroy(); } finally { channel = null; // monitor = null; monitorCreated.set(false); channelType = null; channelPut = null; channelPutValueField = null; channelPutCreated.set(false); } }
@Override protected boolean isWriteConnected(PVAChannelHandler channel) { // NOTE: access-rights not yet supported final Channel c = channel.getChannel(); return c != null && c.isConnected(); }
@Override public boolean isConnected(PVAChannelHandler channel) { final Channel c = channel.getChannel(); return c != null && c.isConnected(); }
@Override public void channelCreated(Status status, Channel channel) { reportStatus("Failed to create channel instance '" + channel.getChannelName(), status); this.channel = channel; }