01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: /**
19: * @author Boris Kuznetsov
20: * @version $Revision$
21: */package org.apache.harmony.xnet.provider.jsse;
22:
23: import org.apache.harmony.xnet.provider.jsse.HandshakeProtocol;
24:
25: import java.security.AccessControlContext;
26: import java.security.AccessController;
27: import java.security.PrivilegedActionException;
28: import java.security.PrivilegedExceptionAction;
29:
30: /**
31: * Delegated Runnable task for SSLEngine
32: */
33: public class DelegatedTask implements Runnable {
34:
35: private final HandshakeProtocol handshaker;
36: private final PrivilegedExceptionAction action;
37: private final AccessControlContext context;
38:
39: /**
40: * Creates DelegatedTask
41: * @param action
42: * @param handshaker
43: * @param context
44: */
45: public DelegatedTask(PrivilegedExceptionAction action,
46: HandshakeProtocol handshaker, AccessControlContext context) {
47: this .action = action;
48: this .handshaker = handshaker;
49: this .context = context;
50: }
51:
52: /**
53: * Executes DelegatedTask
54: */
55: public void run() {
56: synchronized (handshaker) {
57: try {
58: AccessController.doPrivileged(action, context);
59: } catch (PrivilegedActionException e) {
60: // pass exception to HandshakeProtocol
61: handshaker.delegatedTaskErr = e.getException();
62: } catch (RuntimeException e) {
63: // pass exception to HandshakeProtocol
64: handshaker.delegatedTaskErr = e;
65: }
66: }
67:
68: }
69: }
|