1 4 package org.jfox.jms.connector; 5 6 import java.util.ArrayList ; 7 import java.util.HashMap ; 8 import java.util.List ; 9 import java.util.Map ; 10 11 import org.jfox.jms.JMSConnectionRemote; 12 13 16 17 public class ConnectionMeta { 18 19 private String connectionId; 20 private JMSConnectionRemote conn; 21 22 private boolean started = false; 23 24 private Map <String , SessionMeta> sessions = new HashMap <String , SessionMeta>(); 25 26 public ConnectionMeta(String connectionId, JMSConnectionRemote conn) { 27 this.connectionId = connectionId; 28 this.conn = conn; 29 } 30 31 public void registerSession(String sessionId) { 32 SessionMeta sessionMeta = new SessionMeta(sessionId, this); 33 sessions.put(sessionId, sessionMeta); 34 } 35 36 public SessionMeta getSession(String sessionId) { 37 return sessions.get(sessionId); 38 } 39 40 public void unregisterSession(String sessionId) { 41 sessions.remove(sessionId); 42 } 43 44 public JMSConnectionRemote getJMSConnection() { 45 return conn; 46 } 47 48 public boolean isStarted() { 49 return started; 50 } 51 52 public void start() { 53 this.started = true; 54 for (SessionMeta meta : sessions.values()) { 55 synchronized (meta) { 56 meta.notifyAll(); 57 } 58 } 59 } 60 61 public void stop() { 62 this.started = false; 63 } 64 65 public String getConnectionId() { 66 return connectionId; 67 } 68 69 public void close() { 71 List <SessionMeta> list = new ArrayList <SessionMeta>(sessions.values()); 72 for (SessionMeta session : list) { 73 session.close(); 74 } 75 } 76 77 public static void main(String [] args) { 78 79 } 80 } 81 82 | Popular Tags |