Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Kurilov committed Jan 13, 2017
1 parent 2af05c6 commit 373b121
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions common/src/main/java/com/emc/mongoose/common/net/ServiceUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,12 @@ public static String create(final Service svc, final int port) {
final String svcName = svc.getName();
final String svcUri = getLocalSvcUri(svcName, port).toString();
synchronized(SVC_MAP) {
if(! SVC_MAP.containsKey(svcUri)) {
if(!SVC_MAP.containsKey(svcUri)) {
Naming.rebind(svcUri, svc);
SVC_MAP.put(svcName, svc);
System.out.println(
"Registered new service \"" + svcName + "\", total count: " + SVC_MAP.size()
);
} else {
throw new IllegalStateException("Service already registered");
}
Expand Down Expand Up @@ -137,17 +140,23 @@ public static <S extends Service> S resolve(

public static String close(final Service svc)
throws RemoteException, MalformedURLException {
final String svcName = svc.getName();
String svcUri = null;
try {
UnicastRemoteObject.unexportObject(svc, true);
} finally {
try {
svcUri = getLocalSvcUri(svc.getName(), svc.getRegistryPort()).toString();
svcUri = getLocalSvcUri(svcName, svc.getRegistryPort()).toString();
Naming.unbind(svcUri);
synchronized(SVC_MAP) {
if(null == SVC_MAP.remove(svc.getName())) {
if(null == SVC_MAP.remove(svcName)) {
System.err.println(
"Failed to remove the service \"" + svc.getName() + "\""
"Failed to remove the service \"" + svcName + "\""
);
} else {
System.out.println(
"Removed the service \"" + svcName + "\", total count: " +
SVC_MAP.size()
);
}
}
Expand Down

0 comments on commit 373b121

Please sign in to comment.