01: /*
02: *
03: *
04: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26:
27: package com.sun.midp.services;
28:
29: import com.sun.cldc.isolate.*;
30: import com.sun.midp.links.*;
31: import java.io.*;
32:
33: final class SystemServiceRequestHandler {
34: final static String SERVICE_TO_CLIENT_LINK_NAME = "Service to client service request link";
35:
36: final static String CLIENT_TO_SERVICE_LINK_NAME = "Client to service service request link";
37:
38: private SystemServiceManager serviceManager = null;
39:
40: class IsolateRequestHandlerThread extends Thread {
41: private IsolateSystemServiceRequestHandler requestHandler = null;
42:
43: IsolateRequestHandlerThread(
44: IsolateSystemServiceRequestHandler requestHandler) {
45: this .requestHandler = requestHandler;
46: }
47:
48: public void run() {
49: SystemServiceConnectionLinks requestLinks = requestHandler
50: .getSendReceiveLinks();
51:
52: Link receiveLink = requestLinks.getReceiveLink();
53:
54: try {
55: while (true) {
56: LinkMessage msg = receiveLink.receive();
57: requestHandler.handleServiceRequest();
58: }
59: } catch (ClosedLinkException cle) {
60: // do nothing
61: } catch (InterruptedIOException iioe) {
62: requestLinks.close();
63: } catch (IOException ioe) {
64: requestLinks.close();
65: }
66: }
67: }
68:
69: SystemServiceRequestHandler(SystemServiceManager serviceManager) {
70: this .serviceManager = serviceManager;
71: }
72:
73: IsolateSystemServiceRequestHandler newIsolateRequestHandler(
74: Isolate clientIsolate) {
75:
76: IsolateSystemServiceRequestHandler requestHandler = null;
77: requestHandler = new IsolateSystemServiceRequestHandler(
78: serviceManager, clientIsolate);
79: SystemServiceConnectionLinks requestLinks = requestHandler
80: .getSendReceiveLinks();
81:
82: NamedLinkPortal
83: .putLink(
84: SystemServiceRequestHandler.SERVICE_TO_CLIENT_LINK_NAME,
85: requestLinks.getSendLink());
86: NamedLinkPortal
87: .putLink(
88: SystemServiceRequestHandler.CLIENT_TO_SERVICE_LINK_NAME,
89: requestLinks.getReceiveLink());
90:
91: return requestHandler;
92: }
93:
94: void handleIsolateRequests(
95: IsolateSystemServiceRequestHandler requestHandler) {
96: new IsolateRequestHandlerThread(requestHandler).start();
97: }
98:
99: }
|