forked from zeroc-ice/ice-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DispatchInterceptorI.java
65 lines (57 loc) · 1.99 KB
/
DispatchInterceptorI.java
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
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//
import com.zeroc.demos.Database.library.Demo.*;
import java.util.concurrent.CompletionStage;
import com.zeroc.Ice.DispatchInterceptor;
import com.zeroc.Ice.OutputStream;
import com.zeroc.Ice.Request;
import com.zeroc.Ice.UserException;
class DispatchInterceptorI extends DispatchInterceptor
{
@Override
public CompletionStage<OutputStream> dispatch(Request request)
throws UserException
{
// Allocate a new SQLRequestContext associated with this
// request thread.
SQLRequestContext context = new SQLRequestContext();
try
{
CompletionStage<OutputStream> stage = _servant.ice_dispatch(request);
assert(stage == null); // We don't use asynchronous dispatch (AMD) with this demo
context.destroyFromDispatch(true);
return stage;
}
catch(JDBCException ex)
{
// Log the error.
com.zeroc.Ice.Current c = request.getCurrent();
context.error("call of `" + c.operation + "' on id `" + c.id.category + "/" + c.id.name + "' failed", ex);
// A JDBCException causes the current transaction to
// rollback.
context.destroyFromDispatch(false);
// Translate the exception to UnknownException.
com.zeroc.Ice.UnknownException e = new com.zeroc.Ice.UnknownException();
e.initCause(ex);
throw e;
}
catch(UserException ex)
{
// A user exception causes the transaction to rollback.
context.destroyFromDispatch(false);
throw ex;
}
catch(RuntimeException ex)
{
// Any other exception causes the transaction to rollback.
context.destroyFromDispatch(false);
throw ex;
}
}
DispatchInterceptorI(com.zeroc.Ice.Object servant)
{
_servant = servant;
}
private com.zeroc.Ice.Object _servant;
}