Skip to content

Commit 5590114

Browse files
authored
Merge pull request #52 from epics-base/Issue_51
Issue 51
2 parents fc5be1f + 9ccb2a7 commit 5590114

4 files changed

Lines changed: 33 additions & 30 deletions

File tree

pvAccessJava/src/org/epics/pvaccess/client/impl/remote/search/SimpleChannelSearchManagerImpl.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,11 @@ private void boost()
418418
// for (SearchInstance si : sis)
419419
// si.getUserValue().set(BOOST_VALUE);
420420
// }
421-
422-
for(SearchInstance searchInstance : channels.values()) {
423-
searchInstance.getUserValue().set(BOOST_VALUE);
424-
}
421+
synchronized (channels) {
422+
for (SearchInstance searchInstance : channels.values()) {
423+
searchInstance.getUserValue().set(BOOST_VALUE);
424+
}
425+
}
425426
}
426427

427428
@Override
@@ -439,12 +440,12 @@ public void callback() {
439440
try
440441
{
441442
SearchInstance[] sis;
442-
//synchronized (channels) {
443+
synchronized (channels) {
443444
if (channels.size() == 0)
444445
return;
445446
sis = new SearchInstance[channels.size()];
446447
channels.values().toArray(sis);
447-
//}
448+
}
448449

449450
send(sis);
450451
}

pvAccessJava/src/org/epics/pvaccess/impl/remote/TransportRegistry.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,15 @@ public void put(Transport transport) {
5757
// TODO support type
5858
final short priority = transport.getPriority();
5959
final InetSocketAddress address = transport.getRemoteAddress();
60-
Map<Short, Transport> priorities = transports.get(address);
61-
if (priorities == null) {
62-
priorities = Collections.synchronizedMap(new HashMap<Short, Transport>());
63-
transports.put(address, priorities);
64-
}
65-
priorities.put(priority, transport);
66-
allTransports.add(transport);
67-
60+
synchronized (transports) {
61+
Map<Short, Transport> priorities = transports.get(address);
62+
if (priorities == null) {
63+
priorities = Collections.synchronizedMap(new HashMap<Short, Transport>());
64+
transports.put(address, priorities);
65+
}
66+
priorities.put(priority, transport);
67+
allTransports.add(transport);
68+
}
6869
}
6970

7071
/**
@@ -78,7 +79,7 @@ public void put(Transport transport) {
7879
* priority of the transport.
7980
* @return corresponding transport, <code>null</code> if none found.
8081
*/
81-
public Transport get(String type, InetSocketAddress address, short priority) {
82+
public synchronized Transport get(String type, InetSocketAddress address, short priority) {
8283
// TODO support type
8384
Map<Short, Transport> priorities = transports.get(address);
8485
if (priorities != null)
@@ -96,7 +97,7 @@ public Transport get(String type, InetSocketAddress address, short priority) {
9697
* address of the host computer.
9798
* @return array of corresponding transports, <code>null</code> if none found.
9899
*/
99-
public Transport[] get(String type, InetSocketAddress address) {
100+
public synchronized Transport[] get(String type, InetSocketAddress address) {
100101
// TODO support type
101102
Map<Short, Transport> priorities = transports.get(address);
102103
if (priorities != null) {
@@ -115,7 +116,7 @@ public Transport[] get(String type, InetSocketAddress address) {
115116
* transport to remove.
116117
* @return removed transport, <code>null</code> if none found.
117118
*/
118-
public Transport remove(Transport transport) {
119+
public synchronized Transport remove(Transport transport) {
119120
// TODO support type
120121
final short priority = transport.getPriority();
121122
final InetSocketAddress address = transport.getRemoteAddress();
@@ -135,7 +136,7 @@ public Transport remove(Transport transport) {
135136
/**
136137
* Clear cache.
137138
*/
138-
public void clear() {
139+
public synchronized void clear() {
139140

140141
transports.clear();
141142

@@ -147,7 +148,7 @@ public void clear() {
147148
*
148149
* @return number of active (cached) transports.
149150
*/
150-
public int numberOfActiveTransports() {
151+
public synchronized int numberOfActiveTransports() {
151152

152153
return allTransports.size();
153154

@@ -160,7 +161,7 @@ public int numberOfActiveTransports() {
160161
* protocol type (e.g. tcp, udp, ssl, etc.).
161162
* @return array of all active (cached) transports.
162163
*/
163-
public Transport[] toArray(String type) {
164+
public synchronized Transport[] toArray(String type) {
164165
// TODO support type
165166

166167
return allTransports.toArray(new Transport[transports.size()]);
@@ -172,7 +173,7 @@ public Transport[] toArray(String type) {
172173
*
173174
* @return array of all active (cached) transports.
174175
*/
175-
public Transport[] toArray() {
176+
public synchronized Transport[] toArray() {
176177

177178
return allTransports.toArray(new Transport[transports.size()]);
178179

pvAccessJava/src/org/epics/pvaccess/server/impl/remote/ServerChannelImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public Destroyable getRequest(int id) {
158158

159159
}
160160

161-
public Destroyable[] getRequests() {
161+
public synchronized Destroyable[] getRequests() {
162162

163163
Destroyable[] reqs = new Destroyable[requests.size()];
164164
requests.values().toArray(reqs);

pvAccessJava/src/org/epics/pvaccess/server/impl/remote/tcp/NonBlockingServerTCPTransport.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,13 @@ private void destroyAllChannels() {
108108

109109
context.getLogger().fine("Transport to " + socketAddress + " still has " + channels.size() + " channel(s) active and closing...");
110110

111-
112-
for(ServerChannel serverChannel : channels.values()) {
113-
serverChannel.destroy();
114-
}
115-
116-
channels.clear();
111+
synchronized (channels) {
112+
for (ServerChannel serverChannel : channels.values()) {
113+
serverChannel.destroy();
114+
}
115+
116+
channels.clear();
117+
}
117118
}
118119

119120
/**
@@ -122,13 +123,13 @@ private void destroyAllChannels() {
122123
*/
123124
public int preallocateChannelSID()
124125
{
125-
126+
synchronized (channels) {
126127
// search first free (theoretically possible loop of death)
127128
int sid = lastChannelSID.incrementAndGet();
128129
while (channels.containsKey(sid))
129130
sid = lastChannelSID.incrementAndGet();
130131
return sid;
131-
132+
}
132133
}
133134

134135
/**

0 commit comments

Comments
 (0)