protected void createService() throws Exception { super.createService(); // Add a well-known MC alias that other beans can depend on addCanonicalAlias(); }
protected void startService() throws Exception { super.startService(); // Register with the service locator HAPartitionLocator.getHAPartitionLocator().registerHAPartition(this); // Bind ourself in the public JNDI space if configured to do so if (this.bindIntoJndi) { Context ctx = new InitialContext(); this.bind(HAPartitionLocator.getStandardJndiBinding(this.getPartitionName()), this, ClusterPartition.class, ctx); this.log.debug("Bound in JNDI under /HAPartition/" + this.getPartitionName()); } }
public ClusterPartition() { this.logHistory("Partition object created"); }
/** * Adds an alias to our controller context -- the concatenation of * {@link #getAliasPrefix()} and {@link #getPartitionName()}. * This mechanism allows Ejb2HAPartitionDependencyDeployer to add * dependencies to deployments based on the partition name specified in * their metadata, without needing to know the bean name of this partition. */ private void addCanonicalAlias() { if (kernelControllerContext != null) { KernelController kc = (KernelController) kernelControllerContext.getController(); String aliasName = getHaPartitionDependencyCreator().getHAPartitionDependencyName(this.getPartitionName()); try { kc.addAlias(aliasName, kernelControllerContext.getName()); } catch (Throwable t) { log.error("Failed adding alias " + aliasName + " to context " + kernelControllerContext.getName(), t); } } }
@ManagementOperation(description="List all known DistributedReplicantManager keys and the nodes that have registered bindings", impact=Impact.ReadOnly) public String listDRMContent() throws Exception { DistributedReplicantManagerImpl drm = getDistributedReplicantManagerImpl(); return drm == null ? null : drm.listContent(); }
@ManagementOperation(description="Start the HAPartition", impact=Impact.WriteOnly) @Override public void start() throws Exception { if (this.kernelControllerContext != null) pojoChange(ControllerState.START); else super.start(); }
@Override protected void destroyService() { removeCanonicalAlias(); super.destroyService(); }
protected void stopService() throws Exception { super.stopService(); if (this.bindIntoJndi) { String boundName = HAPartitionLocator.getStandardJndiBinding(this.getPartitionName()); InitialContext ctx = null; try { // the following statement fails when the server is being shut down (07/19/2007) ctx = new InitialContext(); ctx.unbind(boundName); } catch (Exception e) { this.log.error("partition unbind operation failed", e); } finally { if (ctx != null) { ctx.close(); } } NonSerializableFactory.unbind(boundName); } HAPartitionLocator.getHAPartitionLocator().deregisterHAPartition(this); }
/** * Removes the alias created in {@link #addCanonicalAlias()} */ private void removeCanonicalAlias() { if (kernelControllerContext != null) { KernelController kc = (KernelController) kernelControllerContext.getController(); String aliasName = getHaPartitionDependencyCreator().getHAPartitionDependencyName(this.getPartitionName()); Set<Object> aliases = kernelControllerContext.getAliases(); if (aliases != null && aliases.contains(aliasName)) { try { kc.removeAlias(aliasName); } catch (Throwable t) { log.error("Failed removing alias " + aliasName + " from context " + kernelControllerContext.getName(), t); } } } }
@ManagementOperation(description="List in XML format all known DistributedReplicantManager keys and the nodes that have registered bindings", impact=Impact.ReadOnly) public String listDRMContentAsXml() throws Exception { DistributedReplicantManagerImpl drm = getDistributedReplicantManagerImpl(); return drm == null ? null : drm.listXmlContent(); }
@ManagementOperation(description="Destroy the HAPartition", impact=Impact.WriteOnly) @Override public void destroy() { if (this.kernelControllerContext != null) pojoChange(ControllerState.CONFIGURED); else super.destroy(); }
@ManagementOperation(description="Get a collection of the names of all keys for which the DistributedReplicantManager has bindings", impact=Impact.ReadOnly) public Collection<String> getDRMServiceNames() { DistributedReplicantManagerImpl drm = getDistributedReplicantManagerImpl(); return drm == null ? null : drm.getAllServices(); }
@ManagementOperation(description="Create the HAPartition", impact=Impact.WriteOnly) @Override public void create() throws Exception { if (this.kernelControllerContext != null) pojoChange(ControllerState.CREATE); else super.create(); }
@ManagementOperation(description="Returns the names of the nodes that have registered objects with the DistributedReplicantManager under the given key", impact=Impact.ReadOnly, params={@ManagementParameter(name="key", description="The name of the service")}) public List<String> lookupDRMNodeNames(String key) { DistributedReplicantManagerImpl drm = getDistributedReplicantManagerImpl(); return drm == null ? null : drm.lookupReplicantsNodeNames(key); }
@ManagementOperation(description="Stop the HAPartition", impact=Impact.WriteOnly) @Override public void stop() { if (this.kernelControllerContext != null) pojoChange(ControllerState.CREATE); else super.stop(); }
@ManagementOperation(description="Returns a hash of the list of nodes that " + "have registered an object with the DistributedReplicantManager under the given key", impact=Impact.ReadOnly, params={@ManagementParameter(name="key", description="The name of the service")}) public int getDRMServiceViewId(String key) { DistributedReplicantManagerImpl drm = getDistributedReplicantManagerImpl(); return drm == null ? null : drm.getReplicantsViewId(key); }
@ManagementOperation(description="Returns whether the DistributedReplicantManager considers this node to be the master for the given service", impact=Impact.ReadOnly, params={@ManagementParameter(name="key", description="The name of the service")}) public boolean isDRMMasterForService(String key) { DistributedReplicantManagerImpl drm = getDistributedReplicantManagerImpl(); return drm == null ? null : drm.isMasterReplica(key); }