Skip to content

Commit

Permalink
Merge pull request #9 from mohrezaei/fixurl
Browse files Browse the repository at this point in the history
for socket server, fix url to service local map
  • Loading branch information
mohrezaei authored Nov 6, 2019
2 parents 5a98195 + 1002c90 commit 1609ded
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
11 changes: 11 additions & 0 deletions src/main/java/com/gs/jrpip/server/ServiceDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
class ServiceDefinition
{
private final Object service;
private Class serviceInterface;
private final MethodResolver methodResolver;
private final boolean isVmBound;
private final OutputStreamBuilder outputStreamBuilder;
Expand All @@ -22,6 +23,16 @@ protected ServiceDefinition(
this.isVmBound = isVmBound;
}

public Class getServiceInterface()
{
return serviceInterface;
}

public void setServiceInterface(Class serviceInterface)
{
this.serviceInterface = serviceInterface;
}

public OutputStreamBuilder getOutputStreamBuilder()
{
return this.outputStreamBuilder;
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/com/gs/jrpip/server/SocketServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public class SocketServer
private AtomicInteger methodInvocations = new AtomicInteger();
private AtomicInteger thankYous = new AtomicInteger();
private AtomicInteger resendRequests = new AtomicInteger();
private String webapp;
private long startTime;
private final HashSet<String> registeredUrls = new HashSet<>();
private boolean binaryLoggingEnabled;
Expand Down Expand Up @@ -99,7 +98,6 @@ public void destroy()
public void start() throws IOException
{
this.startTime = System.currentTimeMillis();
this.webapp = "DEFAULTJRPIP";

initConfig();

Expand Down Expand Up @@ -181,13 +179,11 @@ private void initConfig()
serviceClass.getName(), interfaceClass.getName());
}
Object service = cfg.getOrConstructService();
if (serviceImplementsInterface)
{
JrpipServiceRegistry.getInstance().addServiceForWebApp(this.webapp, interfaceClass, service);
}
MethodResolver methodResolver = new MethodResolver(serviceClass);
this.serviceMap.put(interfaceClass.getName(), new ServiceDefinition(service, methodResolver,
this.initializeOutputStreamBuilder(interfaceClass), cfg.isVmBound()));
ServiceDefinition value = new ServiceDefinition(service, methodResolver,
this.initializeOutputStreamBuilder(interfaceClass), cfg.isVmBound());
value.setServiceInterface(interfaceClass);
this.serviceMap.put(interfaceClass.getName(), value);
}
if (this.serviceMap.isEmpty())
{
Expand Down Expand Up @@ -443,7 +439,11 @@ private void serviceInitRequest(boolean auth, boolean encrypt) throws IOExceptio
{
if (!registeredUrls.contains(url))
{
JrpipServiceRegistry.getInstance().registerWebAppAtUrl(webapp, url);
for(ServiceDefinition serviceDefinition: serviceMap.values())
{
JrpipServiceRegistry.getInstance().addServiceForUrl(url,
serviceDefinition.getServiceInterface(), serviceDefinition.getService());
}
registeredUrls.add(url);
}
}
Expand Down

0 comments on commit 1609ded

Please sign in to comment.