Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * OfficeFloor - http://www.officefloor.net
   * Copyright (C) 2005-2011 Daniel Sagenschneider
   *
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 package net.officefloor.plugin.autowire;
 
 import java.util.List;
 import java.util.Set;
 
 
AutoWireOfficeFloorMBean implementation.

Author(s):
Daniel Sagenschneider
 
 public class AutoWireOfficeFloor implements AutoWireOfficeFloorMBean {

Name value for the AutoWireOfficeFloor MBean.
 
 	public static final String MBEAN_NAME = "AutoWireOfficeFloor";

Obtains the index for the next javax.management.ObjectName to ensure uniqueness.
 
 	private static int nextNameIndex = 0;

javax.management.QueryExp to search for the AutoWireOfficeFloor instances.
 
 	private static QueryExp SEARCH_QUERY;
 
 	static {
 		try {
 			 = new ObjectName("officefloor:type="
 					+ AutoWireOfficeFloor.class.getName() + ",name="
 					+  + "*");
 		} catch (Exception ex) {
 			// This should never be the case
 		}
 	}

Creates the AutoWireOfficeFloor.

Returns:
AutoWireOfficeFloor.
Throws:
java.lang.Exception If fails to create the AutoWireOfficeFloor.
 
 	public static synchronized AutoWireOfficeFloor createAutoWireOfficeFloor(
 			OfficeFloor officeFloorString officeNamethrows Exception {
 
 		// Obtain the unique index for the OfficeFloor
 		int index = ++; // increment for next
 
 		// Create the Object Name
 		ObjectName objectName = new ObjectName("officefloor:type="
 				+ AutoWireOfficeFloor.class.getName() + ",name=" + 
 				+ "_" + index);
 
 		// Create the auto-wire OfficeFloor
 		AutoWireOfficeFloor autoWire = new AutoWireOfficeFloor(officeFloor,
 				officeNameobjectName);
 
 		// Register the auto-wire OfficeFloor
 		ManagementFactory.getPlatformMBeanServer().registerMBean(autoWire,
 				objectName);
 
 		// Return the auto-wire OfficeFloor
 		return autoWire;
 	}

Obtains the AutoWireOfficeFloorMBean instances.

Returns:
AutoWireOfficeFloorMBean instances.
		// Obtain the MBean Server
		MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
		// Obtain the AutoWireOfficeFloor MBean names
		Set<ObjectNamenames = mbeanServer.queryNames(null);
		// Create the listing of the AutoWireOfficeFloor MBeans
				names.size());
		for (ObjectName name : names) {
			AutoWireOfficeFloorMBean mbean = JMX.newMBeanProxy(mbeanServer,
			mbeans.add(mbean);
		}
		// Return the MBeans
		return mbeans.toArray(new AutoWireOfficeFloorMBean[mbeans.size()]);
	}

Convenience method to ensure all AutoWireOfficeFloor instances are closed.
	public static void closeAllOfficeFloors() {
		}
	}

	private final OfficeFloor officeFloor;

	private final String officeName;

	private final ObjectName objectName;

	private AutoWireOfficeFloor(OfficeFloor officeFloorString officeName,
			ObjectName objectName) {
		this. = officeFloor;
		this. = officeName;
		this. = objectName;
	}

		return this.;
	}

		return this.;
	}

Invokes a net.officefloor.frame.api.execute.Task on the net.officefloor.frame.api.manage.OfficeFloor.

Should the net.officefloor.frame.api.manage.OfficeFloor not be open, it is opened before invoking the net.officefloor.frame.api.execute.Task. Please note however the net.officefloor.frame.api.manage.OfficeFloor will not be re-opened after being closed.

Parameters:
workName Name of the net.officefloor.frame.api.execute.Work.
taskName Name of the net.officefloor.frame.api.execute.Task.
parameter Parameter for the net.officefloor.frame.api.execute.Task. May be null.
Returns:
AutoWireOfficeFloor.
Throws:
java.lang.Exception If fails invoking the net.officefloor.frame.api.execute.Task.
	public void invokeTask(String workNameString taskNameObject parameter)
			throws Exception {
		// Obtain the Task
		Office office = this..getOffice(this.);
		WorkManager workManager = office.getWorkManager(workName);
		TaskManager taskManager = workManager.getTaskManager(taskName);
		// Invoke the task
		ProcessContextTeam.doTask(taskManagerparameter);
	}
	/*
	 * ==================== AutoWireOfficeFloorMBean =====================
	 */
	public void invokeTask(String workNameString taskNamethrows Exception {
		this.invokeTask(workNametaskNamenull);
	}
	public void closeOfficeFloor() {
		// Close the OfficeFloor
		// Ensure unregistered
		try {
			MBeanServer mbeanServer = ManagementFactory
			if (mbeanServer.isRegistered(this.)) {
				mbeanServer.unregisterMBean(this.);
			}
catch (Exception ex) {
					"Should not fail to unregister OfficeFloor MBean"ex);
		}
	}
New to GrepCode? Check out our FAQ X