KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > jms > connector > ConnectionMeta


1 /*
2  * Copyright (c) 2004 Your Corporation. All Rights Reserved.
3  */

4 package org.jfox.jms.connector;
5
6 import java.util.ArrayList JavaDoc;
7 import java.util.HashMap JavaDoc;
8 import java.util.List JavaDoc;
9 import java.util.Map JavaDoc;
10
11 import org.jfox.jms.JMSConnectionRemote;
12
13 /**
14  * @author <a HREF="mailto:yy.young@gmail.com">Young Yang</a>
15  */

16
17 public class ConnectionMeta {
18
19     private String JavaDoc connectionId;
20     private JMSConnectionRemote conn;
21
22     private boolean started = false;
23
24     private Map JavaDoc<String JavaDoc, SessionMeta> sessions = new HashMap JavaDoc<String JavaDoc, SessionMeta>();
25
26     public ConnectionMeta(String JavaDoc connectionId, JMSConnectionRemote conn) {
27         this.connectionId = connectionId;
28         this.conn = conn;
29     }
30
31     public void registerSession(String JavaDoc sessionId) {
32         SessionMeta sessionMeta = new SessionMeta(sessionId, this);
33         sessions.put(sessionId, sessionMeta);
34     }
35
36     public SessionMeta getSession(String JavaDoc sessionId) {
37         return sessions.get(sessionId);
38     }
39
40     public void unregisterSession(String JavaDoc 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 JavaDoc getConnectionId() {
66         return connectionId;
67     }
68
69     //TODO: close
70
public void close() {
71         List JavaDoc<SessionMeta> list = new ArrayList JavaDoc<SessionMeta>(sessions.values());
72         for (SessionMeta session : list) {
73             session.close();
74         }
75     }
76
77     public static void main(String JavaDoc[] args) {
78
79     }
80 }
81
82
Popular Tags