Search in sources :

Example 1 with ComponentSpec

use of si.ijs.maci.ComponentSpec in project ACS by ACS-Community.

the class JDynAct method startDynamicComponent.

/** Start a dynamic component
	 * Some of the paraeters may be a '*' instead of a full specified string
	 * 
	 * @param Name The name of the dynamic component
	 * @param IDL The idl interface
	 * @param Implementation The implementation 
	 * @param Container The container
	 * 
	 */
private void startDynamicComponent(String Name, String IDL, String Implementation, String Container) {
    boolean activated;
    // Check if a dynamic component with the same name was already activated
    MyTableModel myModel = (MyTableModel) activatedT.getModel();
    if (myModel.exist(Name)) {
        JOptionPane.showOptionDialog(this, "The component " + Name + " already exists", "Error activating the component", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, null, null);
        return;
    }
    // Start the dynamic component....
    String activatedComponentUrl = null;
    if (theClient.hasFreeSlot()) {
        ComponentSpec compSpec = new ComponentSpec(Name, IDL, Implementation, Container);
        try {
            activatedComponentUrl = theClient.getDynamicComponent(compSpec, false);
        } catch (Exception ce) {
            System.err.println("Error activating the component: " + ce.toString());
            ce.printStackTrace(System.err);
            activated = false;
        }
        // The component is activated => add a new entry in the GUI
        if (activatedComponentUrl != null) {
            myModel.append(Name, activatedComponentUrl);
        } else {
            JOptionPane.showOptionDialog(this, "Dynamic activation error", "Error activating the component", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, null, null);
        }
    } else
        JOptionPane.showOptionDialog(this, "No free slot available", "Error activating the component", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, null, null);
}
Also used : ComponentSpec(si.ijs.maci.ComponentSpec)

Example 2 with ComponentSpec

use of si.ijs.maci.ComponentSpec in project ACS by ACS-Community.

the class PubSubComponentAccessUtil method getDynamicSupplierComponent.

public CorbaNotifySupplierOperations getDynamicSupplierComponent(String componentName, String containerName, ImplLangT implLang) throws AcsJContainerServicesEx {
    String code = null;
    switch(implLang.getType()) {
        case ImplLangT.JAVA_TYPE:
            // Cannot use class#getName because the component helper is not visible to the normal client classloader
            code = "acs.benchmark.nc.comp.publisher.CorbaNotifySupplierComponentHelper";
            break;
        default:
            throw new IllegalArgumentException("Component impl '" + implLang.toString() + "' not yet supported!");
    }
    ComponentSpec compSpec = new ComponentSpec(componentName, // "IDL:alma/benchmark/CorbaNotifySupplier:1.0" 
    CorbaNotifySupplierHelper.id(), code, containerName);
    return getDynamicComponent(compSpec, CorbaNotifySupplierOperations.class);
}
Also used : ComponentSpec(si.ijs.maci.ComponentSpec)

Example 3 with ComponentSpec

use of si.ijs.maci.ComponentSpec in project ACS by ACS-Community.

the class ComponentQueryDescriptor method toComponentSpec.

/**
	 * To be used by the container to get the <code>ComponentSpec</code>
	 * that will be sent to the manager over CORBA.
	 * <p>
	 * <code>null</code> values will be converted automatically into {@link #ANY}.
	 * 
	 * @return filled with name and type from this class, ANY for code and container name.
	 */
public ComponentSpec toComponentSpec() {
    ComponentSpec corbaSpec = new ComponentSpec();
    corbaSpec.component_name = (m_compName != null ? m_compName : ANY);
    corbaSpec.component_type = (m_compType != null ? m_compType : ANY);
    corbaSpec.component_code = ANY;
    corbaSpec.container_name = ANY;
    return corbaSpec;
}
Also used : ComponentSpec(si.ijs.maci.ComponentSpec)

Example 4 with ComponentSpec

use of si.ijs.maci.ComponentSpec in project ACS by ACS-Community.

the class ManagerDynComponentTest method test.

/**
	 * Main test routine.
	 */
public void test() {
    initializeCORBA();
    Manager manager = resolveManager();
    if (manager != null) {
        ClientInfo clientInfo = login(manager);
        if (clientInfo != null) {
            System.out.println("All initialization done.");
            try {
                /* ------------------------------------------------- */
                manager.restart_component(clientInfo.h, "invalid");
                manager.get_component(clientInfo.h, "MOUNT1", true);
                manager.restart_component(clientInfo.h, "MOUNT1");
                try {
                    manager.get_default_component(clientInfo.h, "invalid");
                    System.err.println("NoDefaultComponent exception expected.");
                } catch (NoDefaultComponentEx nde) {
                // this is OK
                }
                try {
                    manager.get_dynamic_component(clientInfo.h, new ComponentSpec("*", "invalidType", "*", "*"), true);
                    System.err.println("InvalidComponentSpec exception expected.");
                } catch (InvalidComponentSpecEx ics) {
                // this is OK
                }
                /* ------------------------------------------------- */
                ComponentInfo componentInfo = manager.get_dynamic_component(clientInfo.h, new ComponentSpec("FULL_DYNAMIC", "IDL:alma/PS/PowerSupply:1.0", "acsexmplPS", "Container"), true);
                System.out.println(componentInfo.h);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            logout(manager, clientInfo);
        }
    }
    finalizeCORBA();
}
Also used : InvalidComponentSpecEx(alma.maciErrType.InvalidComponentSpecEx) ClientInfo(si.ijs.maci.ClientInfo) ComponentInfo(si.ijs.maci.ComponentInfo) POAManager(org.omg.PortableServer.POAManager) Manager(si.ijs.maci.Manager) ComponentSpec(si.ijs.maci.ComponentSpec) NoDefaultComponentEx(alma.maciErrType.NoDefaultComponentEx)

Example 5 with ComponentSpec

use of si.ijs.maci.ComponentSpec in project ACS by ACS-Community.

the class managerClientTest method testGetManyComponents.

public void testGetManyComponents() {
    final String compNameHeader = "DUMMY_COMP_";
    final AtomicInteger sequenceNumber = new AtomicInteger(0);
    totalComponents = 20000;
    totalContainers = 60;
    nThreads = 10;
    class ComponentGetter implements Callable<Boolean> {

        int components, containers;

        ComponentGetter(int components, int containers) {
            this.components = components;
            this.containers = containers;
        }

        public Boolean call() throws Exception {
            int j;
            String compName, contName;
            ComponentSpec corbaSpec = new ComponentSpec();
            corbaSpec.component_type = "IDL:alma/managertest/DummyComponent:1.0";
            corbaSpec.component_code = COMPONENT_SPEC_ANY.value;
            for (int i = 0; i < components; i++) {
                j = sequenceNumber.getAndIncrement();
                compName = compNameHeader + (j + 1);
                contName = "javaContainer" + (j % containers + 1);
                corbaSpec.component_name = compName;
                corbaSpec.container_name = contName;
                //we just loose this reference
                try {
                    ComponentInfo cInfo = null;
                    //Using AcsManagerProxy directly to set the value of Container
                    cInfo = m_acsManagerProxy.get_dynamic_component(m_acsManagerProxy.getManagerHandle(), corbaSpec, false);
                    DummyComponent d = DummyComponentHelper.narrow(cInfo.reference);
                    if (d == null)
                        return false;
                    d.doNothing();
                } catch (Exception e) {
                //do nothing, keep trying other components
                }
            //TODO:here we can give maybe the comp number to see when the program crashed?
            //double ret = d.returnAttributeValue(5);
            //if (ret != 5) return false; 
            }
            return true;
        }
    }
    ExecutorService pool = Executors.newFixedThreadPool(totalComponents, getContainerServices().getThreadFactory());
    CountDownLatch synchCreationStart = new CountDownLatch(totalComponents);
    List<Future<Boolean>> results = new ArrayList<Future<Boolean>>();
    //Components must be multiple of the threads
    try {
        for (int i = 0; i < nThreads; i++) {
            results.add(pool.submit(new ComponentGetter(totalComponents / nThreads, totalContainers)));
        }
        pool.shutdown();
        int n = 0;
        while (!pool.isTerminated()) {
            n++;
            Thread.sleep(60 * 1000);
            m_logger.info("Waiting 60 seconds more. Total now is " + n + " minutes.");
        }
        //}
        for (Future<Boolean> future : results) {
            try {
                Boolean threadResult = future.get();
                if (!threadResult)
                    m_logger.info("The thead couldn't get a reference");
                m_logger.info("CARLI b=" + threadResult);
                assertTrue(threadResult);
            } catch (ExecutionException ex) {
                m_logger.info("Unexpected exception 1" + ex.getCause().toString());
            } catch (Throwable thr) {
                m_logger.info("Unexpected exception 2" + thr.toString());
            }
        }
    } catch (InterruptedException e) {
        assertTrue(false);
        m_logger.info("A timeout occurs when waiting the tasks to finish execution" + e);
    } finally {
        try {
            //sleep 1 minute
            Thread.sleep(60 * 1000);
        } catch (InterruptedException e) {
        }
        //release all components
        for (int i = 0; i < totalComponents; i++) {
            getContainerServices().releaseComponent(compNameHeader + i);
        }
        assertTrue(false);
    }
}
Also used : ArrayList(java.util.ArrayList) ComponentSpec(si.ijs.maci.ComponentSpec) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutionException(java.util.concurrent.ExecutionException) Callable(java.util.concurrent.Callable) DummyComponent(alma.managertest.DummyComponent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) ComponentInfo(si.ijs.maci.ComponentInfo) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

ComponentSpec (si.ijs.maci.ComponentSpec)7 ExecutionException (java.util.concurrent.ExecutionException)2 Future (java.util.concurrent.Future)2 ComponentInfo (si.ijs.maci.ComponentInfo)2 InstrumentedFutureTask (acs.benchmark.util.ConcurrentComponentAccessUtil.InstrumentedFutureTask)1 InvalidComponentSpecEx (alma.maciErrType.InvalidComponentSpecEx)1 NoDefaultComponentEx (alma.maciErrType.NoDefaultComponentEx)1 DummyComponent (alma.managertest.DummyComponent)1 MountOperations (alma.testManager.MountOperations)1 ArrayList (java.util.ArrayList)1 Vector (java.util.Vector)1 Callable (java.util.concurrent.Callable)1 CancellationException (java.util.concurrent.CancellationException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 POAManager (org.omg.PortableServer.POAManager)1 ClientInfo (si.ijs.maci.ClientInfo)1 Manager (si.ijs.maci.Manager)1