Skip to content

Commit

Permalink
Initial fix of Java demos (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier authored Dec 10, 2024
1 parent 00482e3 commit 700c4b3
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 24 deletions.
14 changes: 7 additions & 7 deletions java/Ice/interceptor/InterceptorI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

import com.zeroc.demos.Ice.interceptor.Demo.*;
import com.zeroc.Ice.Current;
import com.zeroc.Ice.Request;
import com.zeroc.Ice.IncomingRequest;
import com.zeroc.Ice.OutgoingResponse;
import java.util.concurrent.CompletionStage;
import java.util.Set;

class InterceptorI extends com.zeroc.Ice.DispatchInterceptor
class InterceptorI implements com.zeroc.Ice.Object
{
InterceptorI(com.zeroc.Ice.Object servant, AuthenticatorI authenticator, Set<String> securedOperations)
{
Expand All @@ -18,20 +19,19 @@ class InterceptorI extends com.zeroc.Ice.DispatchInterceptor
}

@Override
public CompletionStage<com.zeroc.Ice.OutputStream> dispatch(Request request)
public CompletionStage<OutgoingResponse> dispatch(IncomingRequest request)
throws com.zeroc.Ice.UserException
{
Current current = request.getCurrent();
//
// Check if the operation requires authorization to invoke.
//
if(_securedOperations.contains(current.operation))
if(_securedOperations.contains(request.current.operation))
{
//
// Validate the client's access token before dispatching to the servant.
// 'validateToken' throws an exception if the token is invalid or expired.
//
String tokenValue = current.ctx.get("accessToken");
String tokenValue = request.current.ctx.get("accessToken");
if(tokenValue != null)
{
_authenticator.validateToken(tokenValue);
Expand All @@ -44,7 +44,7 @@ public CompletionStage<com.zeroc.Ice.OutputStream> dispatch(Request request)
throw new AuthorizationException();
}
}
return _servant.ice_dispatch(request);
return _servant.dispatch(request);
}

private final com.zeroc.Ice.Object _servant;
Expand Down
2 changes: 1 addition & 1 deletion java/Ice/interrupt/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ else if(line.equals("b"))
{
System.out.println("blocking task " + id + " interrupted");
}
catch(com.zeroc.Ice.Exception e)
catch(com.zeroc.Ice.LocalException e)
{
System.out.println("blocking task " + id + " failed");
e.printStackTrace();
Expand Down
11 changes: 4 additions & 7 deletions java/Ice/interrupt/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ public static void main(String[] args)
// By using an executor it is straightforward to interrupt any servant
// dispatch threads by using ExecutorService.shutdownNow.
//
final ExecutorService executor = Executors.newFixedThreadPool(5);
initData.dispatcher = (runnable, con) ->
{
executor.submit(runnable);
};
final ExecutorService executorService = Executors.newFixedThreadPool(5);
initData.executor = (runnable, con) -> executorService.submit(runnable);

//
// Try with resources block - communicator is automatically destroyed
Expand All @@ -41,7 +38,7 @@ public static void main(String[] args)
//
Runtime.getRuntime().addShutdownHook(new Thread(() ->
{
executor.shutdownNow();
executorService.shutdownNow();
communicator.destroy();
}));

Expand All @@ -53,7 +50,7 @@ public static void main(String[] args)
else
{
com.zeroc.Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TaskManager");
adapter.add(new TaskManagerI(executor), com.zeroc.Ice.Util.stringToIdentity("manager"));
adapter.add(new TaskManagerI(executorService), com.zeroc.Ice.Util.stringToIdentity("manager"));
adapter.activate();

communicator.waitForShutdown();
Expand Down
8 changes: 3 additions & 5 deletions java/Ice/invoke/PrinterI.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,9 @@ else if(current.operation.equals("shutdown"))
}
else
{
com.zeroc.Ice.OperationNotExistException ex = new com.zeroc.Ice.OperationNotExistException();
ex.id = current.id;
ex.facet = current.facet;
ex.operation = current.operation;
throw ex;
// No need to specify the identity/facet/operation: Ice fills them in automatically
// using 'current'.
throw new com.zeroc.Ice.OperationNotExistException();
}

//
Expand Down
2 changes: 1 addition & 1 deletion java/Ice/swing/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static void main(final String[] args)
initData.properties = new com.zeroc.Ice.Properties();
initData.properties.load("config.client");
initData.properties.setProperty("Ice.Default.Package", "com.zeroc.demos.Ice.swing");
initData.dispatcher = (runnable, connection) -> SwingUtilities.invokeLater(runnable);
initData.executor = (runnable, connection) -> SwingUtilities.invokeLater(runnable);

_communicator = com.zeroc.Ice.Util.initialize(args, initData);
Runtime.getRuntime().addShutdownHook(new Thread(() -> _communicator.destroy()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,14 @@ else if(m.what == MSG_EXCEPTION || m.what == MSG_RESPONSE)
WifiManager.MulticastLock lock = wifiManager.createMulticastLock("com.zeroc.hello");
lock.acquire();


// SSL initialization can take some time. To avoid blocking the
// calling thread, we perform the initialization in a separate thread.
new Thread(() -> {
try
{
InitializationData initData = new InitializationData();

initData.dispatcher = (Runnable runnable, Connection connection) ->
_uiHandler.post(runnable);
initData.executor = (Runnable runnable, Connection connection) -> _uiHandler.post(runnable);

initData.properties = Util.createProperties();
initData.properties.setProperty("Ice.Trace.Network", "3");
Expand Down

0 comments on commit 700c4b3

Please sign in to comment.