protected void lockedStart() throws Exception { super.lockedStart(); this.registerWithAopDispatcher(); // Obtain registrar JndiSessionRegistrarBase registrar = this.getJndiRegistrar(); // Bind all appropriate references/factories to Global JNDI for Client access, if a JNDI Registrar is present if (registrar != null) { String guid = Ejb3Registry.guid(this); registrar.bindEjb(this.getInitialContext(), this.getMetaData(), this.getClassloader(), this.getObjectName() .getCanonicalName(), guid, this.getAdvisor()); } else { log.debug("No " + JndiSessionRegistrarBase.class.getSimpleName() + " was found; bypassing binding of Proxies to " + this.getName() + " in Global JNDI."); } }
public JBossSessionBeanMetaData getMetaData() { // TODO: resolve this cast using generics on EJBContainer return (JBossSessionBeanMetaData) getXml(); }
protected void reinitialize() { super.reinitialize(); singleton = super.construct(); invokeOptionalMethod(METHOD_NAME_LIFECYCLE_CALLBACK_CREATE); }
protected SessionProxyFactory getProxyFactory(RemoteBinding binding) { assert binding!=null : RemoteBinding.class.getSimpleName() + " must be specified"; // Get the Registry name String proxyFactoryRegistryBindName = this.getJndiRegistrar().getProxyFactoryRegistryKey(binding.jndiBinding(), this.getMetaData(), true); // Return return this.getProxyFactory(proxyFactoryRegistryBindName); }
protected void lockedStop() throws Exception { try { Dispatcher.singleton.unregisterTarget(getObjectName().getCanonicalName()); } catch (Exception ignore) { log.debug("Dispatcher unregister target failed", ignore); } // Deregister with Remoting Dispatcher.singleton.unregisterTarget(this.getName()); // Unbind applicable JNDI Entries JndiSessionRegistrarBase jndiRegistrar = this.getJndiRegistrar(); if (jndiRegistrar != null) { jndiRegistrar.unbindEjb(this.getInitialContext(), this.getMetaData()); } super.lockedStop(); }
return this.getInitialContext().lookup(this.getMetaData().getHomeJndiName()); destroySession(id); Exception newException = (Exception) this.constructProperNoSuchEjbException(nsee, invokingClassName); throw newException;
JBossSessionBeanMetaData smd= (JBossSessionBeanMetaData) container.getXml(); CollectionHelper.addAllIfSet(businessInterfaceNames, smd.getBusinessRemotes()); CollectionHelper.addAllIfSet(businessInterfaceNames, smd.getBusinessLocals()); if(((JBossSessionBean31MetaData) smd).isNoInterfaceBean() && businessInterface.equals(container.getBeanClass())) return createNoInterfaceBusinessObject(container, sessionId, businessInterface); throw new IllegalStateException("Cannot find BusinessObject for interface: " + interfaceName); String jndiName = container.getXml().determineResolvedJndiName(interfaceName); return businessInterface.cast(container.getInitialContext().lookup(jndiName));
public void initializeRemoteBindingMetadata() remoteBindings = container.getAnnotation(RemoteBindings.class); if (remoteBindings == null) RemoteBinding binding = container.getAnnotation(RemoteBinding.class); if (binding == null) log.debug("no declared remote bindings for : " + container.getEjbName()); BusinessRemotesMetaData businessRemotes = container.getMetaData().getBusinessRemotes(); if (businessRemotes != null && businessRemotes.size() > 0) log.debug("there is remote interfaces for " + container.getEjbName()); String jndiName = container.getMetaData().getJndiName(); log.debug("default remote binding has jndiName of " + jndiName); String uri = ""; // use the default RemoteBinding[] list = {new RemoteBindingImpl(jndiName, "", uri, "")}; remoteBindings = new RemoteBindingsImpl(list); container.getAnnotations().addClassAnnotation(RemoteBindings.class, remoteBindings); container.getAnnotations().addClassAnnotation(RemoteBindings.class, remoteBindings); container.getAnnotations().addClassAnnotation(RemoteBindings.class, remoteBindings);
private <B> B createNoInterfaceBusinessObject(SessionContainer container, Serializable sessionId, Class<B> businessInterface) throws NamingException { // we have determined it's the no-interface, let's hack JBossSessionBean31MetaData beanMetaData = (JBossSessionBean31MetaData) container.getMetaData(); // get no-interface view jndi name String noInterfaceJndiName = this.getJNDINameResolver(beanMetaData).resolveNoInterfaceJNDIName(beanMetaData); return businessInterface.cast(container.getInitialContext().lookup(noInterfaceJndiName)); }
public <B> B createBusinessObject(SessionContainer container, Serializable sessionId, Class<B> intf) { assert sessionId == null : "sessionId is must be null for Stateless"; assert intf != null : "intf is null"; try { /* * Get all business interfaces */ Set<String> businessInterfaceNames = new HashSet<String>(); JBossSessionBeanMetaData smd= (JBossSessionBeanMetaData) container.getXml(); CollectionHelper.addAllIfSet(businessInterfaceNames, smd.getBusinessRemotes()); CollectionHelper.addAllIfSet(businessInterfaceNames, smd.getBusinessLocals()); String interfaceName = intf.getName(); if (!businessInterfaceNames.contains(interfaceName)) throw new IllegalStateException("Cannot find BusinessObject for interface: " + interfaceName); String jndiName = container.getXml().determineResolvedJndiName(interfaceName); return intf.cast(container.getInitialContext().lookup(jndiName)); } catch (NamingException e) { throw new RuntimeException("failed to invoke getBusinessObject", e); } } }
protected <B> B createNoInterfaceView(SessionContainer container, Serializable sessionId, Class<B> intf) { Class<?> beanClass = container.getBeanClass(); String name = container.getDeploymentQualifiedName(); KernelControllerContext endpointContext = (KernelControllerContext) kernel.getController().getContext(name, null); AsyncMethodsMetaData asyncMethods = null; JBossEnterpriseBeanMetaData sessionBeanMetaData = container.getXml(); if (sessionBeanMetaData instanceof JBossSessionBean31MetaData) { asyncMethods = ((JBossSessionBean31MetaData) sessionBeanMetaData).getAsyncMethods(); } // create an invocation handler InvocationHandler invocationHandler = new NoInterfaceViewInvocationHandler(endpointContext, sessionId, intf, asyncMethods == null ? new AsyncMethodsMetaData() : asyncMethods); // Now create the proxy Object noInterfaceView = new JavassistProxyFactory().createProxy(new Class<?>[] {beanClass}, invocationHandler); return intf.cast(noInterfaceView); }
protected ViewType getViewType(SessionContainer container, Class<?> intf) { // try to see if we can pass the preconditions of LegacyStatefulBusinessObjectFactory? // a direct copy out of LegacyStatefulBusinessObjectFactory // less risky than rolling our own thing. Class<?>[] remoteInterfaces = ProxyFactoryHelper.getRemoteAndBusinessRemoteInterfaces(container); if(arrayContains(remoteInterfaces, intf)) return ViewType.REMOTE; Class<?>[] localInterfaces = ProxyFactoryHelper.getLocalAndBusinessLocalInterfaces(container); if(arrayContains(localInterfaces, intf)) return ViewType.LOCAL; // copied out of EJB3NoInterfaceDeployer JBossSessionBeanMetaData beanMetaData = container.getMetaData(); if(!(beanMetaData instanceof JBossSessionBean31MetaData)) return ViewType.UNKNOWN; JBossSessionBean31MetaData sessionBean31MetaData = (JBossSessionBean31MetaData) beanMetaData; if(!sessionBean31MetaData.isNoInterfaceBean()) return ViewType.UNKNOWN; // it could still be an unknown view, make sure it's the no-interface view if(intf.equals(container.getBeanClass())) return ViewType.NO_INTERFACE; return ViewType.UNKNOWN; }
JBossSessionBeanMetaData smd = container.getMetaData();
public void create() throws Exception { super.create(); // EJBTHREE-2046: a hack, because we want to construct before startup if(getBeanInstantiator() == null) { log.warn("EJBTHREE-2046: beanInstantior not set, using default on " + this); // TODO: should not introduce an EJB 3.1 dependency setBeanInstantiator(new Ejb31SpecBeanInstantiator()); } // EJBTHREE-655: fire up an instance for use as MBean delegate singleton = super.construct(); registerManagementInterface(); invokeOptionalMethod(METHOD_NAME_LIFECYCLE_CALLBACK_CREATE); }
public Serializable createSession() { return createSession(new Class<?>[]{}, new Object[]{}); }
public void destroy() throws Exception { // Make the lifecycle callback invokeOptionalMethod(METHOD_NAME_LIFECYCLE_CALLBACK_DESTROY); // Unregister w/ MBean Server unregisterManagementInterface(); // Null out singleton = null; beanContext = null; // Call super impl super.destroy(); }
protected Object invokeLocal(Invocation invocation, Container container) throws Throwable { Invocation copy = marshallOrPass(invocation, Invocation.class); copy.getMetaData().addMetaData(IS_LOCAL, IS_LOCAL, Boolean.TRUE, PayloadKey.AS_IS); try { // Invoke upon the container SessionContainer sc = (SessionContainer) container; InvocationResponse response = sc.dynamicInvoke(copy); // it could really have been a copy invocation.setResponseContextInfo(response.getContextInfo()); return marshallOrPass(response.getResponse(), Object.class); } // TODO: Either Throwable (as it used to be) or Exception (which is better) catch(Throwable t) { throw marshallOrPass(t, Throwable.class); } finally { copy.getMetaData().removeMetaData(IS_LOCAL, IS_LOCAL); } }
protected SessionProxyFactory getProxyFactory(LocalBinding binding) { assert binding!=null : LocalBinding.class.getSimpleName() + " must be specified"; // Find the jndiName String jndiName = this.getMetaData().getLocalJndiName(); if(binding!=null) { jndiName = binding.jndiBinding(); } // Get the Registry name String proxyFactoryRegistryBindName = this.getJndiRegistrar().getProxyFactoryRegistryKey(jndiName, this.getMetaData(), true); // Return return this.getProxyFactory(proxyFactoryRegistryBindName); }
/** * A direct copy out of LegacyStatefulBusinessObjectFactory */ protected <B> B createLegacyBusinessObject(SessionContainer container, Serializable sessionId, Class<B> businessInterface, ViewType type) { boolean isRemote = type == ViewType.REMOTE; // Obtain SFSB JNDI Registrar String sfsbJndiRegistrarObjectStoreBindName = ((StatefulContainer) container).getJndiRegistrarBindName(); JndiStatefulSessionRegistrar sfsbJndiRegistrar = Ejb3RegistrarLocator.locateRegistrar().lookup( sfsbJndiRegistrarObjectStoreBindName, JndiStatefulSessionRegistrar.class); // Get the metadata JBossSessionBeanMetaData smd = container.getMetaData(); // Get the appropriate JNDI Name String jndiName = !isRemote ? smd.getLocalJndiName() : smd.getJndiName(); // Find the Proxy Factory Key for this SFSB String proxyFactoryKey = sfsbJndiRegistrar.getProxyFactoryRegistryKey(jndiName, smd, !isRemote); // Lookup the Proxy Factory in the Object Store StatefulSessionProxyFactory proxyFactory = Ejb3RegistrarLocator.locateRegistrar().lookup(proxyFactoryKey, StatefulSessionProxyFactory.class); // Create a new business proxy Object proxy = proxyFactory.createProxyBusiness(sessionId, businessInterface.getName()); // Return the Proxy return businessInterface.cast(proxy); }