20 package org.vortex.FACE;
22 import java.util.ArrayList;
23 import java.util.concurrent.locks.Lock;
24 import java.util.concurrent.locks.ReadWriteLock;
25 import java.util.concurrent.locks.ReentrantReadWriteLock;
27 import org.omg.dds.core.AlreadyClosedException;
28 import org.omg.dds.core.status.Status;
29 import org.omg.dds.domain.DomainParticipant;
30 import org.omg.dds.domain.DomainParticipantFactory;
31 import org.omg.dds.domain.DomainParticipantQos;
32 import org.omg.dds.topic.Topic;
33 import org.omg.dds.topic.TopicQos;
35 import FACE.CONNECTION_DIRECTION_TYPE;
36 import FACE.TRANSPORT_CONNECTION_STATUS_TYPE;
37 import FACE.VALIDITY_TYPE;
41 private final Class<TYPE> dataType;
42 private DomainParticipant participant;
43 private Topic<TYPE> topic;
44 private TRANSPORT_CONNECTION_STATUS_TYPE status;
45 private final ReadWriteLock readWriteLock =
new ReentrantReadWriteLock();
46 private final Lock
readLock = readWriteLock.readLock();
47 private final Lock
writeLock = readWriteLock.writeLock();
50 this.description = description;
51 this.dataType = dataType;
52 this.setupParticipant();
54 this.status =
new TRANSPORT_CONNECTION_STATUS_TYPE(0, 1, 0,
56 VALIDITY_TYPE.INVALID);
59 public TRANSPORT_CONNECTION_STATUS_TYPE
getStatus() {
60 return new TRANSPORT_CONNECTION_STATUS_TYPE(this.status.MAX_MESSAGE,
61 this.status.MAX_MESSAGE_SIZE,
this.status.MESSAGE,
62 this.status.CONNECTION_DIRECTION,
63 this.status.WAITING_PROCESSES_OR_MESSAGES,
64 this.status.REFRESH_PERIOD,
this.status.LAST_MSG_VALIDITY);
69 this.status.LAST_MSG_VALIDITY = lastMessageValidity;
73 public abstract CONNECTION_DIRECTION_TYPE
getDirection();
76 return this.description;
80 return this.participant;
87 private void setupParticipant() {
88 DomainParticipantFactory df = this.description.getEnvironment()
89 .getSPI().getParticipantFactory();
91 DomainParticipantQos qos = this.description.getDomainParticipantQos();
94 qos = df.getDefaultParticipantQos();
96 this.participant = df.createParticipant(this.description.getDomainId(),
97 qos, null,
new ArrayList<Class<? extends Status>>());
100 private void setupTopic() {
101 TopicQos qos = this.description.getTopicQos();
104 qos = this.participant.getDefaultTopicQos();
106 this.topic = this.participant.createTopic(
107 this.description.getTopicName(), this.dataType, qos, null,
108 new ArrayList<Class<? extends Status>>());
126 this.participant.close();
127 }
catch(AlreadyClosedException e) {
133 @SuppressWarnings(
"unchecked")
139 }
catch (ClassCastException c) {
146 if (this.
getDirection() != CONNECTION_DIRECTION_TYPE.DESTINATION) {
153 if (this.
getDirection() != CONNECTION_DIRECTION_TYPE.SOURCE) {
160 this.readLock.lock();
164 this.readLock.unlock();
168 this.writeLock.lock();
172 this.writeLock.unlock();
DomainParticipant getParticipant()
DestinationConnection< TYPE > asDestination()
abstract CONNECTION_DIRECTION_TYPE getDirection()
TRANSPORT_CONNECTION_STATUS_TYPE getStatus()
static< TYPE > Connection< TYPE > getConnection(ConnectionDescription description, Class< TYPE > dataType)
SourceConnection< TYPE > asSource()
void setLastMessageValidity(VALIDITY_TYPE lastMessageValidity)
This is a typed class which will be generated by idlpp.
CONNECTION_DIRECTION_TYPE getDirection()
Connection(ConnectionDescription description, Class< TYPE > dataType)
ConnectionDescription getDescription()