001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)ComponentRunnable.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: /**
030: * ComponentRunnable.java
031: *
032: * SUN PROPRIETARY/CONFIDENTIAL.
033: * This software is the proprietary information of Sun Microsystems, Inc.
034: * Use is subject to license terms.
035: *
036: * Created on December 15, 2005, 11:56 AM
037: */package com.sun.jbi.management.registry.xml;
038:
039: import com.sun.jbi.ComponentInfo;
040: import com.sun.jbi.ComponentState;
041: import com.sun.jbi.ComponentType;
042: import com.sun.jbi.ServiceUnitInfo;
043: import com.sun.jbi.ServiceUnitState;
044:
045: import com.sun.jbi.management.registry.Updater;
046: import com.sun.jbi.management.registry.Registry;
047: import com.sun.jbi.management.registry.data.ComponentInfoImpl;
048: import com.sun.jbi.management.registry.data.ServiceUnitInfoImpl;
049:
050: import java.util.Calendar;
051:
052: /**
053: *
054: * @author Sun Microsystems, Inc.
055: */
056: public class ComponentRunnable implements Runnable {
057: private Registry mRegistry;
058: private String mTstComp;
059: private boolean mAdd;
060: private Updater mUpdater;
061:
062: /** Creates a new instance of ComponentRunnable */
063: public ComponentRunnable(Registry registry, String componentName,
064: boolean add) throws Exception {
065: mUpdater = registry.getUpdater();
066: mTstComp = componentName;
067: mAdd = add;
068: }
069:
070: public void run() {
071: try {
072: if (mAdd) {
073: addComponent();
074: }
075: } catch (Exception ex) {
076: ex.printStackTrace();
077: }
078: }
079:
080: public void addComponent() throws Exception {
081: try {
082:
083: // Add a Component
084: ComponentInfo comp = createTestComponent(mTstComp);
085:
086: mUpdater.addComponent(mTstComp, mTstComp + "File", Calendar
087: .getInstance());
088: mUpdater.addComponent("another-server", comp);
089: } catch (Throwable ex) {
090: ex.printStackTrace();
091: throw new Exception(ex);
092: }
093: }
094:
095: private ComponentInfo createTestComponent(String compName) {
096: ComponentInfoImpl component = new ComponentInfoImpl();
097:
098: component.setName(compName);
099: component.setWorkspaceRoot("C:/foo");
100: component.setInstallRoot("C:/foo");
101: component.setComponentClassName("SunBPELEngine.class");
102: component.setBootstrapClassLoaderSelfFirst(true);
103: component.setClassLoaderSelfFirst(true);
104: component.setProperty("time", "seconds");
105: component.setProperty("threads", "10");
106: component.setStatus(ComponentState.STOPPED);
107: component.setComponentType(ComponentType.ENGINE);
108: component.addServiceUnitInfo(createTestServiceUnit("SU1"));
109:
110: return component;
111: }
112:
113: private ServiceUnitInfo createTestServiceUnit(String name) {
114: ServiceUnitInfoImpl suinfo = new ServiceUnitInfoImpl();
115: suinfo.setName(name);
116: suinfo.setServiceAssemblyName("CompositeApplication");
117: suinfo.setState(ServiceUnitState.STOPPED);
118:
119: return suinfo;
120: }
121: }
|