1 28 29 package com.caucho.ejb.protocol; 30 31 import com.caucho.ejb.AbstractServer; 32 import com.caucho.log.Log; 33 import com.caucho.util.L10N; 34 import com.caucho.util.LruCache; 35 36 import javax.ejb.EJBHome ; 37 import javax.ejb.EJBLocalHome ; 38 import javax.ejb.EJBObject ; 39 import java.util.logging.Logger ; 40 41 44 public abstract class ClientContainer { 45 protected static L10N L = new L10N(ClientContainer.class); 46 protected static Logger log = Log.open(ClientContainer.class); 47 48 static final String CLIENT_KEY = "caucho.ejb.client"; 49 50 String _serverId; 52 EJBLocalHome _localHomeStub; 54 EJBHome _remoteHomeStub; 56 LruCache<String ,EJBObject > _stubMap = new LruCache<String ,EJBObject >(1024); 58 protected HandleEncoder _handleEncoder; 60 61 66 protected ClientContainer(String serverId) 67 { 68 _serverId = serverId; 69 } 70 71 74 protected String getServerId() 75 { 76 return _serverId; 77 } 78 79 84 public EJBHome getHomeStub() 85 throws Exception 86 { 87 if (_remoteHomeStub != null) 88 return _remoteHomeStub; 89 90 _remoteHomeStub = createHomeStub(); 91 92 return _remoteHomeStub; 93 } 94 95 100 public Object getEJBLocalHome() 101 { 102 AbstractServer jvmServer = EjbProtocolManager.getJVMServer(_serverId); 103 104 return jvmServer.getClientLocalHome(); 105 } 106 107 112 abstract protected EJBHome createHomeStub() 113 throws Exception ; 114 115 public HandleEncoder getHandleEncoder(AbstractHandle handle) 116 { 117 if (_handleEncoder == null) 118 _handleEncoder = new HandleEncoder("foo"); 119 120 return _handleEncoder; 121 } 122 125 public Class getPrimaryKeyClass() 126 { 127 return String .class; 128 } 129 130 137 public EJBObject getObjectStub(String url) 138 throws Exception 139 { 140 EJBObject stub = _stubMap.get(url); 141 if (stub != null) 142 return stub; 143 144 stub = createObjectStub(url); 145 146 _stubMap.put(url, stub); 147 148 return stub; 149 } 150 151 158 abstract protected EJBObject createObjectStub(String url) 159 throws Exception ; 160 161 164 public String toString() 165 { 166 return "ClientContainer[" + _serverId + "]"; 167 } 168 } 169 | Popular Tags |