Skip to content

Commit 0bc28bd

Browse files
committed
Merge pull request igniterealtime#573 from guusdk/OF-1125
OF-1125: Should use StreamID class instead of String.
2 parents 8540446 + 2cc0a94 commit 0bc28bd

25 files changed

+147
-209
lines changed

src/java/org/jivesoftware/openfire/LocalSessionManager.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ class LocalSessionManager {
8989
/**
9090
* The sessions contained in this Map are server sessions originated by a remote server. These
9191
* sessions can only receive packets from the remote server but are not capable of sending
92-
* packets to the remote server. Sessions will be added to this collecion only after they were
92+
* packets to the remote server. Sessions will be added to this collection only after they were
9393
* authenticated.
9494
* Key: streamID, Value: the IncomingServerSession associated to the streamID.
9595
*/
96-
private final Map<String, LocalIncomingServerSession> incomingServerSessions =
96+
private final Map<StreamID, LocalIncomingServerSession> incomingServerSessions =
9797
new ConcurrentHashMap<>();
9898

9999

@@ -109,19 +109,19 @@ public Map<String, LocalConnectionMultiplexerSession> getConnnectionManagerSessi
109109
return connnectionManagerSessions;
110110
}
111111

112-
public LocalIncomingServerSession getIncomingServerSession(String streamID) {
112+
public LocalIncomingServerSession getIncomingServerSession(StreamID streamID) {
113113
return incomingServerSessions.get(streamID);
114114
}
115115

116116
public Collection<LocalIncomingServerSession> getIncomingServerSessions() {
117117
return incomingServerSessions.values();
118118
}
119119

120-
public void addIncomingServerSessions(String streamID, LocalIncomingServerSession session) {
120+
public void addIncomingServerSessions(StreamID streamID, LocalIncomingServerSession session) {
121121
incomingServerSessions.put(streamID, session);
122122
}
123123

124-
public void removeIncomingServerSessions(String streamID) {
124+
public void removeIncomingServerSessions(StreamID streamID) {
125125
incomingServerSessions.remove(streamID);
126126
}
127127

src/java/org/jivesoftware/openfire/SessionManager.java

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,24 @@
2222

2323
import java.net.InetAddress;
2424
import java.util.ArrayList;
25-
import java.util.Arrays;
2625
import java.util.Collection;
2726
import java.util.Collections;
28-
import java.util.Date;
29-
import java.util.Deque;
3027
import java.util.HashSet;
3128
import java.util.Iterator;
3229
import java.util.List;
3330
import java.util.Locale;
3431
import java.util.Map;
35-
import java.util.Map.Entry;
3632
import java.util.Set;
3733
import java.util.concurrent.atomic.AtomicInteger;
3834
import java.util.concurrent.locks.Lock;
3935

40-
import org.dom4j.Element;
4136
import org.jivesoftware.openfire.audit.AuditStreamIDFactory;
4237
import org.jivesoftware.openfire.auth.AuthToken;
4338
import org.jivesoftware.openfire.auth.UnauthorizedException;
4439
import org.jivesoftware.openfire.cluster.ClusterEventListener;
4540
import org.jivesoftware.openfire.cluster.ClusterManager;
4641
import org.jivesoftware.openfire.component.InternalComponentManager;
4742
import org.jivesoftware.openfire.container.BasicModule;
48-
import org.jivesoftware.openfire.disco.DiscoInfoProvider;
49-
import org.jivesoftware.openfire.disco.DiscoItem;
50-
import org.jivesoftware.openfire.disco.DiscoItemsProvider;
51-
import org.jivesoftware.openfire.disco.DiscoServerItem;
52-
import org.jivesoftware.openfire.disco.ServerItemsProvider;
5343
import org.jivesoftware.openfire.event.SessionEventDispatcher;
5444
import org.jivesoftware.openfire.http.HttpConnection;
5545
import org.jivesoftware.openfire.http.HttpSession;
@@ -70,18 +60,13 @@
7060
import org.jivesoftware.openfire.session.RemoteSessionLocator;
7161
import org.jivesoftware.openfire.session.Session;
7262
import org.jivesoftware.openfire.spi.BasicStreamIDFactory;
73-
import org.jivesoftware.openfire.streammanagement.StreamManager;
7463
import org.jivesoftware.openfire.user.UserManager;
75-
import org.jivesoftware.openfire.user.UserNotFoundException;
7664
import org.jivesoftware.util.JiveGlobals;
7765
import org.jivesoftware.util.LocaleUtils;
78-
import org.jivesoftware.util.Log;
79-
import org.jivesoftware.util.XMPPDateTimeFormat;
8066
import org.jivesoftware.util.cache.Cache;
8167
import org.jivesoftware.util.cache.CacheFactory;
8268
import org.slf4j.Logger;
8369
import org.slf4j.LoggerFactory;
84-
import org.xmpp.forms.DataForm;
8570
import org.xmpp.packet.JID;
8671
import org.xmpp.packet.Message;
8772
import org.xmpp.packet.Packet;
@@ -145,15 +130,15 @@ public class SessionManager extends BasicModule implements ClusterEventListener/
145130
* Cache (unlimited, never expire) that holds incoming sessions of remote servers.
146131
* Key: stream ID that identifies the socket/session, Value: nodeID
147132
*/
148-
private Cache<String, byte[]> incomingServerSessionsCache;
133+
private Cache<StreamID, byte[]> incomingServerSessionsCache;
149134
/**
150135
* Cache (unlimited, never expire) that holds list of incoming sessions
151136
* originated from the same remote server (domain/subdomain). For instance, jabber.org
152137
* may have 2 connections to the server running in jivesoftware.com (one socket to
153138
* jivesoftware.com and the other socket to conference.jivesoftware.com).
154139
* Key: remote hostname (domain/subdomain), Value: list of stream IDs that identify each socket.
155140
*/
156-
private Cache<String, List<String>> hostnameSessionsCache;
141+
private Cache<String, List<StreamID>> hostnameSessionsCache;
157142

158143
/**
159144
* Cache (unlimited, never expire) that holds domains, subdomains and virtual
@@ -167,7 +152,7 @@ public class SessionManager extends BasicModule implements ClusterEventListener/
167152
* will have access to this clustered cache even in the case of this node going
168153
* down.
169154
*/
170-
private Cache<String, Set<String>> validatedDomainsCache;
155+
private Cache<StreamID, Set<String>> validatedDomainsCache;
171156

172157
private ClientSessionListener clientSessionListener = new ClientSessionListener();
173158
private ComponentSessionListener componentSessionListener = new ComponentSessionListener();
@@ -465,15 +450,15 @@ public void outgoingServerSessionCreated(LocalOutgoingServerSession session) {
465450
*/
466451
public void registerIncomingServerSession(String hostname, LocalIncomingServerSession session) {
467452
// Keep local track of the incoming server session connected to this JVM
468-
String streamID = session.getStreamID().getID();
453+
StreamID streamID = session.getStreamID();
469454
localSessionManager.addIncomingServerSessions(streamID, session);
470455
// Keep track of the nodeID hosting the incoming server session
471456
incomingServerSessionsCache.put(streamID, server.getNodeID().toByteArray());
472457
// Update list of sockets/sessions coming from the same remote hostname
473458
Lock lock = CacheFactory.getLock(hostname, hostnameSessionsCache);
474459
try {
475460
lock.lock();
476-
List<String> streamIDs = hostnameSessionsCache.get(hostname);
461+
List<StreamID> streamIDs = hostnameSessionsCache.get(hostname);
477462
if (streamIDs == null) {
478463
streamIDs = new ArrayList<>();
479464
}
@@ -508,7 +493,7 @@ public void registerIncomingServerSession(String hostname, LocalIncomingServerSe
508493
*/
509494
public void unregisterIncomingServerSession(String hostname, IncomingServerSession session) {
510495
// Remove local track of the incoming server session connected to this JVM
511-
String streamID = session.getStreamID().getID();
496+
StreamID streamID = session.getStreamID();
512497
localSessionManager.removeIncomingServerSessions(streamID);
513498
// Remove track of the nodeID hosting the incoming server session
514499
incomingServerSessionsCache.remove(streamID);
@@ -517,7 +502,7 @@ public void unregisterIncomingServerSession(String hostname, IncomingServerSessi
517502
Lock lock = CacheFactory.getLock(hostname, hostnameSessionsCache);
518503
try {
519504
lock.lock();
520-
List<String> streamIDs = hostnameSessionsCache.get(hostname);
505+
List<StreamID> streamIDs = hostnameSessionsCache.get(hostname);
521506
if (streamIDs != null) {
522507
streamIDs.remove(streamID);
523508
if (streamIDs.isEmpty()) {
@@ -563,7 +548,7 @@ public void unregisterIncomingServerSession(String hostname, IncomingServerSessi
563548
* @param streamID id that uniquely identifies the session.
564549
* @return domains, subdomains and virtual hosts that where validated.
565550
*/
566-
public Collection<String> getValidatedDomains(String streamID) {
551+
public Collection<String> getValidatedDomains(StreamID streamID) {
567552
Lock lock = CacheFactory.getLock(streamID, validatedDomainsCache);
568553
try {
569554
lock.lock();
@@ -850,7 +835,7 @@ public Collection<ClientSession> getSessions(SessionResultFilter filter) {
850835
* @param streamID the stream ID that identifies the incoming server session hosted by this JVM.
851836
* @return the incoming server session hosted by this JVM or null if none was found.
852837
*/
853-
public LocalIncomingServerSession getIncomingServerSession(String streamID) {
838+
public LocalIncomingServerSession getIncomingServerSession(StreamID streamID) {
854839
return localSessionManager.getIncomingServerSession(streamID);
855840
}
856841

@@ -863,7 +848,7 @@ public LocalIncomingServerSession getIncomingServerSession(String streamID) {
863848
* @return the sessions that were originated by a remote server.
864849
*/
865850
public List<IncomingServerSession> getIncomingServerSessions(String hostname) {
866-
List<String> streamIDs;
851+
List<StreamID> streamIDs;
867852
// Get list of sockets/sessions coming from the remote hostname
868853
Lock lock = CacheFactory.getLock(hostname, hostnameSessionsCache);
869854
try {
@@ -880,7 +865,7 @@ public List<IncomingServerSession> getIncomingServerSessions(String hostname) {
880865
else {
881866
// Collect the sessions associated to the found stream IDs
882867
List<IncomingServerSession> sessions = new ArrayList<>();
883-
for (String streamID : streamIDs) {
868+
for (StreamID streamID : streamIDs) {
884869
// Search in local hosted sessions
885870
IncomingServerSession session = localSessionManager.getIncomingServerSession(streamID);
886871
RemoteSessionLocator locator = server.getRemoteSessionLocator();
@@ -1608,14 +1593,14 @@ private void restoreCacheContent() {
16081593

16091594
// Add incoming server sessions hosted locally to the cache (using new nodeID)
16101595
for (LocalIncomingServerSession session : localSessionManager.getIncomingServerSessions()) {
1611-
String streamID = session.getStreamID().getID();
1596+
StreamID streamID = session.getStreamID();
16121597
incomingServerSessionsCache.put(streamID, server.getNodeID().toByteArray());
16131598
for (String hostname : session.getValidatedDomains()) {
16141599
// Update list of sockets/sessions coming from the same remote hostname
16151600
Lock lock = CacheFactory.getLock(hostname, hostnameSessionsCache);
16161601
try {
16171602
lock.lock();
1618-
List<String> streamIDs = hostnameSessionsCache.get(hostname);
1603+
List<StreamID> streamIDs = hostnameSessionsCache.get(hostname);
16191604
if (streamIDs == null) {
16201605
streamIDs = new ArrayList<>();
16211606
}

src/java/org/jivesoftware/openfire/multiplex/ClientSessionConnection.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package org.jivesoftware.openfire.multiplex;
2222

2323
import org.dom4j.Element;
24+
import org.jivesoftware.openfire.StreamID;
2425
import org.jivesoftware.openfire.XMPPServer;
2526
import org.jivesoftware.openfire.net.VirtualConnection;
2627
import org.jivesoftware.openfire.session.ConnectionMultiplexerSession;
@@ -72,7 +73,7 @@ public ClientSessionConnection(String connectionManagerName, String hostName, St
7273
*/
7374
@Override
7475
public void deliver(Packet packet) {
75-
String streamID = session.getStreamID().getID();
76+
StreamID streamID = session.getStreamID();
7677
ConnectionMultiplexerSession multiplexerSession =
7778
multiplexerManager.getMultiplexerSession(connectionManagerName,streamID);
7879
if (multiplexerSession != null) {
@@ -100,15 +101,15 @@ public void deliver(Packet packet) {
100101
*/
101102
@Override
102103
public void deliverRawText(String text) {
103-
String streamID = session.getStreamID().getID();
104+
StreamID streamID = session.getStreamID();
104105
ConnectionMultiplexerSession multiplexerSession =
105106
multiplexerManager.getMultiplexerSession(connectionManagerName,streamID);
106107
if (multiplexerSession != null) {
107108
// Wrap packet so that the connection manager can figure out the target session
108109
StringBuilder sb = new StringBuilder(200 + text.length());
109110
sb.append("<route from=\"").append(serverName);
110111
sb.append("\" to=\"").append(connectionManagerName);
111-
sb.append("\" streamid=\"").append(streamID).append("\">");
112+
sb.append("\" streamid=\"").append(streamID.getID()).append("\">");
112113
sb.append(text);
113114
sb.append("</route>");
114115
// Deliver the wrapped stanza
@@ -176,7 +177,7 @@ public void systemShutdown() {
176177
@Override
177178
public void closeVirtualConnection() {
178179
// Figure out who requested the connection to be closed
179-
String streamID = session.getStreamID().getID();
180+
StreamID streamID = session.getStreamID();
180181
if (multiplexerManager.getClientSession(connectionManagerName, streamID) == null) {
181182
// Client or Connection manager requested to close the session
182183
// Do nothing since it has already been removed and closed
@@ -192,7 +193,7 @@ public void closeVirtualConnection() {
192193
closeRequest.setTo(connectionManagerName);
193194
Element child = closeRequest.setChildElement("session",
194195
"http://jabber.org/protocol/connectionmanager");
195-
child.addAttribute("id", streamID);
196+
child.addAttribute("id", streamID.getID());
196197
child.addElement("close");
197198
multiplexerSession.process(closeRequest);
198199
}

0 commit comments

Comments
 (0)