1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
/*******************************************************************************
* Copyright (c) 2010 Boeing.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.framework.messaging.internal;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.OseeProperties;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.messaging.ConnectionNode;
import org.eclipse.osee.framework.messaging.ConnectionNodeFactory;
import org.eclipse.osee.framework.messaging.MessageService;
import org.eclipse.osee.framework.messaging.NodeInfo;
/**
* @author Roberto E. Escobar
*/
public class MessageServiceImpl implements MessageService {
private static final String VM_URI = "vm://localhost?broker.persistent=false";
private final NodeInfo defaultNode;
private final Map<NodeInfo, ConnectionNode> connectionNodes;
private final ConnectionNodeFactory factory;
public MessageServiceImpl(ConnectionNodeFactory factory) {
this.connectionNodes = new ConcurrentHashMap<NodeInfo, ConnectionNode>();
this.factory = factory;
defaultNode = new NodeInfo("osee-jms", getDefaultURI());
}
private URI getDefaultURI() {
URI defaultURI = null;
String uri = OseeProperties.getOseeDefaultBrokerUri();
if (uri == null) {
uri = VM_URI;
}
try {
defaultURI = new URI(uri);
} catch (URISyntaxException ex) {
try {
defaultURI = new URI(VM_URI);
} catch (URISyntaxException ex1) {
OseeLog.log(MessageServiceImpl.class, Level.SEVERE, ex1);
}
}
OseeLog.logf(Activator.class, Level.FINER, "Default URI for message Service [%s]", defaultURI.toASCIIString());
return defaultURI;
}
@Override
public ConnectionNode getDefault() throws OseeCoreException {
return get(defaultNode);
}
@Override
public Collection<NodeInfo> getAvailableConnections() {
return new ArrayList<NodeInfo>(connectionNodes.keySet());
}
@Override
public int size() {
return connectionNodes.size();
}
@Override
public boolean isEmpty() {
return connectionNodes.isEmpty();
}
@Override
public ConnectionNode get(NodeInfo nodeInfo) throws OseeCoreException {
ConnectionNode node = connectionNodes.get(nodeInfo);
if (node == null) {
OseeLog.logf(Activator.class, Level.FINEST, "going to create a new Connection Node for [%s]",
nodeInfo.toString());
node = factory.create(nodeInfo);
connectionNodes.put(nodeInfo, node);
OseeLog.logf(Activator.class, Level.FINE, "Created a new Connection Node for [%s]", nodeInfo.toString());
}
return node;
}
void stop() {
for (ConnectionNode node : connectionNodes.values()) {
node.stop();
}
}
}
|