@@ -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
0 commit comments