KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mx4j > tools > remote > caucho > CauchoService


1 /*
2  * Copyright (C) The MX4J Contributors.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the MX4J License version 1.0.
6  * See the terms of the MX4J License in the documentation provided with this software.
7  */

8
9 package mx4j.tools.remote.caucho;
10
11 import java.lang.reflect.Method JavaDoc;
12
13 import mx4j.tools.remote.http.HTTPService;
14
15 /**
16  * @version $
17  */

18 public class CauchoService extends HTTPService
19 {
20    static final String JavaDoc CONNECTION_ID_HEADER_NAME = "connectionContext";
21
22    private static ThreadLocal JavaDoc connectionContext = new ThreadLocal JavaDoc();
23
24    private final String JavaDoc protocol;
25
26    public CauchoService(String JavaDoc protocol)
27    {
28       this.protocol = protocol;
29    }
30
31    protected String JavaDoc getProtocol()
32    {
33       return protocol;
34    }
35
36    protected String JavaDoc findRequestURL()
37    {
38       ConnectionContext context = (ConnectionContext)connectionContext.get();
39       return context == null ? null : context.url;
40    }
41
42    protected String JavaDoc findConnectionId()
43    {
44       ConnectionContext context = (ConnectionContext)connectionContext.get();
45       return context == null ? null : context.connectionId;
46    }
47
48    static void setConnectionContext(String JavaDoc url, String JavaDoc connectionId)
49    {
50       connectionContext.set(new ConnectionContext(url, connectionId));
51    }
52
53    static void resetConnectionContext()
54    {
55       connectionContext.set(null);
56    }
57
58    static String JavaDoc mangleMethodName(Method JavaDoc method)
59    {
60       return method.getName() + "__" + method.getParameterTypes().length;
61    }
62
63    private static class ConnectionContext
64    {
65       private String JavaDoc url;
66       private String JavaDoc connectionId;
67
68       private ConnectionContext(String JavaDoc url, String JavaDoc connectionId)
69       {
70          this.url = url;
71          this.connectionId = connectionId;
72       }
73    }
74 }
75
Popular Tags