Skip to content

Commit 1714e53

Browse files
authored
Merge pull request #55 from epics-base/Issue_53
Issue 53
2 parents 5590114 + 44b89a9 commit 1714e53

File tree

6 files changed

+109
-48
lines changed

6 files changed

+109
-48
lines changed

bundleJava/pom.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@
3232
<!-- The assembly is built through dependencies, as the regular moduleSet
3333
does not allow to include sources and javadoc as jars -->
3434
<dependencies>
35+
<dependency>
36+
<groupId>${project.groupId}</groupId>
37+
<artifactId>epics-util</artifactId>
38+
</dependency>
39+
<dependency>
40+
<groupId>${project.groupId}</groupId>
41+
<artifactId>epics-util</artifactId>
42+
<classifier>sources</classifier>
43+
</dependency>
44+
<dependency>
45+
<groupId>${project.groupId}</groupId>
46+
<artifactId>epics-util</artifactId>
47+
<classifier>javadoc</classifier>
48+
</dependency>
49+
3550
<dependency>
3651
<groupId>${project.groupId}</groupId>
3752
<artifactId>epics-pvdata</artifactId>

epics-core/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
<url>https://github.com/epics-base/epicsCoreJava</url>
1616

1717
<dependencies>
18+
<dependency>
19+
<groupId>${project.groupId}</groupId>
20+
<artifactId>epics-util</artifactId>
21+
</dependency>
1822
<dependency>
1923
<groupId>${project.groupId}</groupId>
2024
<artifactId>epics-pvdata</artifactId>
@@ -30,6 +34,7 @@
3034
<dependency>
3135
<groupId>org.epics</groupId>
3236
<artifactId>jca</artifactId>
37+
<version>${jca.version}</version>
3338
</dependency>
3439
</dependencies>
3540
</project>

epics-vtype/vtype/src/main/java/org/epics/vtype/IVEnumArray.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,23 @@
55

66
import org.epics.util.array.ArrayInteger;
77
import org.epics.util.array.ListInteger;
8+
import org.epics.util.array.ListNumber;
89

910
/**
10-
* Immutable {@code VEnum} implementation.
11+
* Immutable {@code VEnumArray} implementation.
1112
*
1213
* @author carcassi, shroffk, kasemir
1314
*/
1415
public class IVEnumArray extends VEnumArray {
1516

1617
private final Alarm alarm;
1718
private final Time time;
18-
private final ListInteger indices;
19+
private final ListNumber indices;
1920
private final EnumDisplay enumDisplay;
2021

2122
private final List<String> labels;
2223

23-
IVEnumArray(ListInteger indices, EnumDisplay enumDisplay, Alarm alarm, Time time) {
24+
IVEnumArray(ListNumber indices, EnumDisplay enumDisplay, Alarm alarm, Time time) {
2425
VType.argumentNotNull("enumDisplay", enumDisplay);
2526
this.enumDisplay = enumDisplay;
2627

@@ -32,8 +33,8 @@ public class IVEnumArray extends VEnumArray {
3233
for (int i = 0; i < indices.size(); i++) {
3334
int index = indices.getInt(i);
3435
if (index < 0 || index >= enumDisplay.getChoices().size()) {
35-
throw new IndexOutOfBoundsException("VEnumArray element " + i + " has index " + index
36-
+ " outside of permitted options " + enumDisplay.getChoices());
36+
labels.add("VEnumArray element " + i + " has index " + index + " outside of permitted options "
37+
+ enumDisplay.getChoices());
3738
}
3839
labels.add(enumDisplay.getChoices().get(index));
3940
}
@@ -63,7 +64,7 @@ public List<String> getData() {
6364
}
6465

6566
@Override
66-
public ListInteger getIndexes() {
67+
public ListNumber getIndexes() {
6768
return indices;
6869
}
6970

epics-vtype/vtype/src/main/java/org/epics/vtype/VEnumArray.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
import java.util.List;
44

55
import org.epics.util.array.ListInteger;
6+
import org.epics.util.array.ListNumber;
7+
import org.epics.util.array.ListShort;
68

9+
/**
10+
* Scalar enum array with alarm, timestamp, and display information.
11+
*/
712
public abstract class VEnumArray extends Array implements AlarmProvider, TimeProvider {
813

914
/**
10-
*
15+
* Return the enum label values
1116
*/
1217
@Override
1318
public abstract List<String> getData();
@@ -17,7 +22,7 @@ public abstract class VEnumArray extends Array implements AlarmProvider, TimePro
1722
*
1823
* @return an array of indexes
1924
*/
20-
public abstract ListInteger getIndexes();
25+
public abstract ListNumber getIndexes();
2126

2227
/** @return the enum display information, i.e. choices */
2328
public abstract EnumDisplay getDisplay();
@@ -33,4 +38,16 @@ public abstract class VEnumArray extends Array implements AlarmProvider, TimePro
3338
public static VEnumArray of(ListInteger data, EnumDisplay enumDisplay, Alarm alarm, Time time) {
3439
return new IVEnumArray(data, enumDisplay, alarm, time);
3540
}
41+
42+
/**
43+
* Return an instance of the VEnumArray
44+
* @param data the indices
45+
* @param enumDisplay the enum display labels
46+
* @param alarm the alarm
47+
* @param time new time
48+
* @return {@link VEnumArray} instance of VEnumArray
49+
*/
50+
public static VEnumArray of(ListShort data, EnumDisplay enumDisplay, Alarm alarm, Time time) {
51+
return new IVEnumArray(data, enumDisplay, alarm, time);
52+
}
3653
}

pom.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
<properties>
1414
<!-- Matching versions of Core modules -->
15+
<epics-util.version>1.0.1-SNAPSHOT</epics-util.version>
1516
<epics-pvdata.version>6.1.3-SNAPSHOT</epics-pvdata.version>
1617
<epics-ntypes.version>0.3.3-SNAPSHOT</epics-ntypes.version>
1718
<epics-pvaccess.version>5.1.3-SNAPSHOT</epics-pvaccess.version>
@@ -142,6 +143,24 @@
142143
<dependencies>
143144

144145
<!-- EPICS Core Libraries -->
146+
<dependency>
147+
<groupId>org.epics</groupId>
148+
<artifactId>epics-util</artifactId>
149+
<version>${epics-util.version}</version>
150+
</dependency>
151+
<dependency>
152+
<groupId>org.epics</groupId>
153+
<artifactId>epics-util</artifactId>
154+
<version>${epics-util.version}</version>
155+
<classifier>sources</classifier>
156+
</dependency>
157+
<dependency>
158+
<groupId>org.epics</groupId>
159+
<artifactId>epics-util</artifactId>
160+
<version>${epics-util.version}</version>
161+
<classifier>javadoc</classifier>
162+
</dependency>
163+
145164
<dependency>
146165
<groupId>org.epics</groupId>
147166
<artifactId>epics-pvdata</artifactId>

pvAccessJava/src/org/epics/pvaccess/client/impl/remote/ClientContextImpl.java

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -540,22 +540,21 @@ private void internalDestroy() {
540540

541541
}
542542

543-
/**
544-
* Destroy all channels.
545-
*/
546-
private void destroyAllChannels() {
547-
548-
for (Channel channel : channelsByCID.values()) {
549-
try {
550-
channel.destroy();
551-
} catch (Exception e) {
552-
e.printStackTrace();
553-
}
554-
}
555-
556-
channelsByCID.clear();
557-
558-
}
543+
/**
544+
* Destroy all channels.
545+
*/
546+
private void destroyAllChannels() {
547+
synchronized (channelsByCID) {
548+
for (Channel channel : channelsByCID.values()) {
549+
try {
550+
channel.destroy();
551+
} catch (Exception e) {
552+
e.printStackTrace();
553+
}
554+
}
555+
channelsByCID.clear();
556+
}
557+
}
559558

560559
/**
561560
* Check channel name.
@@ -587,7 +586,6 @@ public Channel createChannelInternal(String name, ChannelRequester requester, sh
587586
boolean lockAcquired = namedLocker.acquireSynchronizationObject(name, LOCK_TIMEOUT);
588587
if (lockAcquired) {
589588
try {
590-
591589
int cid = generateCID();
592590
return new ChannelImpl(this, cid, name, requester, priority, addresses);
593591
} finally {
@@ -933,18 +931,23 @@ Transport getTransport(TransportClient client, InetSocketAddress serverAddress,
933931
*
934932
* @return Client channel ID (CID).
935933
*/
936-
private int generateCID() {
937-
// reserve CID
938-
channelsByCID.put(lastCID, null);
939-
return lastCID;
940-
}
934+
private int generateCID() {
935+
synchronized (channelsByCID) {
936+
// reserve CID
937+
// search first free (theoretically possible loop of death)
938+
while (getChannel(++lastCID) != null)
939+
;
940+
// reserve CID
941+
channelsByCID.put(lastCID, null);
942+
return lastCID;
943+
}
944+
}
941945

942946
/**
943947
* Free generated channel ID (CID).
944948
*/
945949
private void freeCID(int cid) {
946950
channelsByCID.remove(cid);
947-
948951
}
949952

950953
/**
@@ -954,10 +957,9 @@ private void freeCID(int cid) {
954957
* I/O ID.
955958
* @return request response with given I/O ID.
956959
*/
957-
public ResponseRequest getResponseRequest(int ioid) {
958-
959-
return (ResponseRequest) pendingResponseRequests.get(ioid);
960-
}
960+
public ResponseRequest getResponseRequest(int ioid) {
961+
return (ResponseRequest) pendingResponseRequests.get(ioid);
962+
}
961963

962964
/**
963965
* Register response request.
@@ -967,10 +969,11 @@ public ResponseRequest getResponseRequest(int ioid) {
967969
* @return request ID (IOID).
968970
*/
969971
public int registerResponseRequest(ResponseRequest request) {
970-
971-
int ioid = generateIOID();
972-
pendingResponseRequests.put(ioid, request);
973-
return ioid;
972+
synchronized (pendingResponseRequests) {
973+
int ioid = generateIOID();
974+
pendingResponseRequests.put(ioid, request);
975+
return ioid;
976+
}
974977

975978
}
976979

@@ -990,15 +993,16 @@ public ResponseRequest unregisterResponseRequest(ResponseRequest request) {
990993
*
991994
* @return IOID.
992995
*/
993-
private int generateIOID() {
994-
995-
// search first free (theoretically possible loop of death)
996-
while (pendingResponseRequests.get(++lastIOID) != null || lastIOID == PVAConstants.PVA_INVALID_IOID)
997-
;
998-
// reserve IOID
999-
pendingResponseRequests.put(lastIOID, null);
1000-
return lastIOID;
1001-
}
996+
private int generateIOID() {
997+
synchronized (pendingResponseRequests) {
998+
// search first free (theoretically possible loop of death)
999+
while (pendingResponseRequests.get(++lastIOID) != null || lastIOID == PVAConstants.PVA_INVALID_IOID)
1000+
;
1001+
// reserve IOID
1002+
pendingResponseRequests.put(lastIOID, null);
1003+
return lastIOID;
1004+
}
1005+
}
10021006

10031007
/**
10041008
* Get (and if necessary create) beacon handler.

0 commit comments

Comments
 (0)