use of si.ijs.maci.ComponentInfo 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);
}
}
use of si.ijs.maci.ComponentInfo in project ACS by ACS-Community.
the class DeploymentTree method showContextMenu.
/**
* @param evt
*/
protected void showContextMenu(MouseEvent evt) {
TreePath targetPath = this.getClosestPathForLocation(evt.getX(), evt.getY());
if (targetPath == null) {
// clicked into a totally empty tree (no manager shown): ignore click.
return;
}
setSelectionPath(targetPath);
if (targetPath.getPathCount() == 1) {
// that has no function besides looking good
return;
}
// the supervisor (which is in the rootnode) for this subtree
selectedSupervisor = maciSupervisor(((SortingTreeNode) targetPath.getPathComponent(1)));
// the node the mouse was clicked on
target = (SortingTreeNode) targetPath.getLastPathComponent();
Object userObject = target.getUserObject();
ContextMenu menu;
if (userObject instanceof IMaciSupervisor) {
menu = managerContextMenu;
} else if (userObject instanceof ContainerInfo) {
menu = containerContextMenu;
} else if (userObject instanceof ClientInfo) {
menu = clientContextMenu;
} else if (userObject instanceof ComponentInfo) {
menu = componentContextMenu;
} else if (userObject instanceof FolderInfo) {
menu = folderContextMenu;
} else if (userObject instanceof InfoDetail) {
// msc 2012-06: help user navigate in large datasets (cf. COMP-3684)
// this menu is built dynamically from rather expensive information.
menu = new ContextMenu(false);
int[] selectedHandles = ((SortingTreeNode) target).representedHandles;
if (selectedHandles.length > 0) {
menu.add(new JLabel(" Scroll to ..."));
menu.add(new JSeparator(JSeparator.HORIZONTAL));
SortingTreeNode mgrNode = (SortingTreeNode) target.getPath()[1];
List<Object> list = new ArrayList<Object>();
list.add(mgrNode);
for (SortingTreeNode top : mgrNode.childrens()) list.addAll(Collections.list(top.children()));
for (Object obj : list) {
final SortingTreeNode elem = (SortingTreeNode) obj;
for (int i = 0; i < selectedHandles.length; i++) {
if (elem.represents(selectedHandles[i])) {
Object elemUserObject = elem.getUserObject();
String elemName = null;
if (elemUserObject instanceof ComponentInfo)
elemName = ((ComponentInfo) elemUserObject).name;
else if (elemUserObject instanceof ContainerInfo)
elemName = ((ContainerInfo) elemUserObject).name;
else if (elemUserObject instanceof ClientInfo)
elemName = ((ClientInfo) elemUserObject).name;
else if (elemUserObject instanceof MaciSupervisor)
elemName = "Manager";
if (elemName != null) {
menu.add(new AbstractAction(selectedHandles[i] + " = " + elemName) {
@Override
public void actionPerformed(ActionEvent evt) {
DeploymentTree.this.scrollPathToVisible(new TreePath(elem.getPath()));
}
});
}
}
}
}
}
} else {
return;
}
menu.show(this, evt.getX(), evt.getY());
}
use of si.ijs.maci.ComponentInfo in project ACS by ACS-Community.
the class MaciInfo method addInfoNodes.
protected void addInfoNodes(SortingTreeNode node, Map<Object, String> auxiliary) {
Object info = node.getUserObject();
int infokey = System.identityHashCode(info);
if (info instanceof ContainerInfo) {
//ContainerInfo casted = (ContainerInfo)info;
node.add(createNode(new InfoDetail("location", auxiliary.get(infokey + ".location"))));
} else if (info instanceof ClientInfo) {
ClientInfo casted = (ClientInfo) info;
node.add(createNode(new InfoDetail("location", auxiliary.get(infokey + ".location"))));
node.add(createNode(new InfoDetail("components", casted.components, true)));
node.add(createNode(new InfoDetail("access", casted.access, false)));
node.add(createNode(new InfoDetail("reference", casted.reference)));
} else if (info instanceof ComponentInfo) {
ComponentInfo casted = (ComponentInfo) info;
node.add(createNode(new InfoDetail("clients", casted.clients, true)));
node.add(createNode(new InfoDetail("container", casted.container, true)));
node.add(createNode(new InfoDetail("container_name", casted.container_name)));
node.add(createNode(new InfoDetail("access", casted.access, false)));
node.add(createNode(new InfoDetail("reference", casted.reference)));
node.add(createNode(new InfoDetail("interfaces", casted.interfaces)));
node.add(createNode(new InfoDetail("type", casted.type)));
node.add(createNode(new InfoDetail("code", casted.code)));
}
}
use of si.ijs.maci.ComponentInfo in project ACS by ACS-Community.
the class MaciInfo method setContents.
/**
* Sets the components, containers, and clients.
* The given lists must not be changed anymore (otherwise
* this method would have to make a copy of them).
*/
protected void setContents(List<ComponentInfo> newComponents, List<ContainerInfo> newContainers, List<ClientInfo> newClientApps, Map<Object, String> auxiliary) {
// bend references, each assignment is atomic and triggers a flush.
// note we shall not modify the lists anymore after this point!
this.components = newComponents;
this.containers = newContainers;
this.clientApps = newClientApps;
// re-populate the toplevel nodes
// ---------------------------------------------
componentNode.removeAllChildren();
for (ComponentInfo comp : newComponents) {
SortingTreeNode n = createNode(comp);
addInfoNodes(n, auxiliary);
componentNode.add(n);
}
containerNode.removeAllChildren();
for (ContainerInfo cont : newContainers) {
SortingTreeNode n = createNode(cont);
addInfoNodes(n, auxiliary);
// attach components that are active in this container
for (ComponentInfo comp : newComponents) {
if (comp.container == cont.h && comp.h != 0)
n.add(createNode(comp));
}
containerNode.add(n);
}
clientNode.removeAllChildren();
for (ClientInfo client : newClientApps) {
SortingTreeNode n = createNode(client);
addInfoNodes(n, auxiliary);
clientNode.add(n);
}
// we sort - for some great user experience
componentNode.sortChildrenByName();
containerNode.sortChildrenByName();
clientNode.sortChildrenByName();
// send out change event
nodeStructureChanged(managerNode);
}
use of si.ijs.maci.ComponentInfo in project ACS by ACS-Community.
the class AcsContainer method activate_component.
/////////////////////////////////////////////////////////////
// Implementation of ContainerOperations#activate_component
/////////////////////////////////////////////////////////////
/**
* Activates a component so that it's ready to receive functional calls
* after returning from this method. Called by the ACS Manager.
* <p>
* From MACI IDL:
* <i>
* Activate a component whose type (class) and name (instance) are given.
* In the process of activation, component's code-base is loaded into memory if it is not there already.
* The code-base resides in an executable file (usually a dynamic-link library or a shared library -- DLL).
* On platforms that do not automatically load dependent executables (e.g., VxWorks),
* the container identifies the dependencies by querying the executable and loads them automatically.
* Once the code is loaded, it is asked to construct a servant of a given type.
* The servant is then initialized with the Configuration Database (CDB) and Persistance Database (PDB) data.
* The servant is attached to the component, and a reference to it is returned.
* </i>
* <p>
* @param componentHandle handle of the component that is being activated. This handle is used
* by the component when it will present itself to the Manager.
* The component is expected to remember this handle for its entire life-time.
* @param execution_id
* @param compName name of the component to instantiate (instance name, comes from CDB)
* @param exe component helper implementation class; must be a subclass of
* {@link alma.acs.container.ComponentHelper}.
* @param type the type of the component to instantiate (Corba IR id).
* @return Returns the reference to the object that has just been activated.
* If the component could not the activated, a nil reference is returned.
*
* @see si.ijs.maci.ContainerOperations#activate_component(int, String, String, String)
*/
public ComponentInfo activate_component(int componentHandle, long execution_id, String compName, String exe, String type) throws CannotActivateComponentEx {
// reject the call if container is shutting down
if (shuttingDown.get()) {
String msg = "activate_component() rejected because of container shutdown.";
m_logger.fine(msg);
AcsJCannotActivateComponentEx ex = new AcsJCannotActivateComponentEx();
ex.setCURL(compName);
ex.setDetailedReason(msg);
throw ex.toCannotActivateComponentEx();
}
ComponentInfo componentInfo = null;
StopWatch activationWatch = new StopWatch(m_logger);
// to make component activations stick out in the log list
m_logger.finer("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
m_logger.fine("activate_component: handle=" + componentHandle + " name=" + compName + " helperClass=" + exe + " type=" + type);
// if the container is still starting up, then hold the request until the container is ready
boolean contInitWaitSuccess = false;
try {
contInitWaitSuccess = containerStartOrbThreadGate.await(30, TimeUnit.SECONDS);
} catch (InterruptedException ex1) {
// just leave contInitWaitSuccess == false
}
if (!contInitWaitSuccess) {
String msg = "Activation of component " + compName + " timed out after 30 s waiting for the container to finish its initialization.";
m_logger.warning(msg);
AcsJCannotActivateComponentEx ex = new AcsJCannotActivateComponentEx();
ex.setCURL(compName);
ex.setDetailedReason(msg);
throw ex.toCannotActivateComponentEx();
}
ComponentAdapter compAdapter = null;
try {
synchronized (m_activeComponentMap) {
ComponentAdapter existingCompAdapter = getExistingComponent(componentHandle, compName, type);
if (existingCompAdapter != null) {
return existingCompAdapter.getComponentInfo();
} else if (!m_activeComponentMap.reserveComponent(componentHandle)) {
AcsJContainerEx ex = new AcsJContainerEx();
ex.setContextInfo("Component with handle '" + componentHandle + "' is already being activated by this container. Manager should have prevented double activation.");
throw ex;
}
}
ClassLoader compCL = null;
// the property 'acs.components.classpath.jardirs' is set by the script acsStartContainer
// to a list of all relevant 'lib/ACScomponents/' directories
String compJarDirs = System.getProperty(AcsComponentClassLoader.PROPERTY_JARDIRS);
if (compJarDirs != null) {
compCL = new AcsComponentClassLoader(Thread.currentThread().getContextClassLoader(), m_logger, compName);
} else {
// fallback: load component impl classes in the global class loader
compCL = Thread.currentThread().getContextClassLoader();
}
// Create component helper using component classloader.
// Note that the base class alma.acs.container.ComponentHelper will still be loaded by the container CL,
// although the current subclassing design is a bit dirtier than it could be in the sense that a mean
// component could deploy modified container classes (e.g. in method getInterfaceTranslator).
// Nothing big to worry about though...
ComponentHelper compHelper = createComponentHelper(compName, exe, compCL);
// Creates component implementation and connects it with the Corba-generated POATie object.
// Objects for container interception ("tight container") and for automatic xml binding class
// de-/serialization are chained up and inserted here. End-to-end they have to translate between the
// operations interface derived from corba IDL and the component's declared internalInterface.
StopWatch compStopWatch = new StopWatch();
ComponentLifecycle compImpl = compHelper.getComponentImpl();
LOG_CompAct_Instance_OK.log(m_logger, compName, compStopWatch.getLapTimeMillis());
//m_logger.finest(compName + " component impl created, with classloader " + compImpl.getClass().getClassLoader().getClass().getName());
Class<? extends ACSComponentOperations> operationsIFClass = compHelper.getOperationsInterface();
Constructor<? extends Servant> poaTieCtor = compHelper.getPOATieClass().getConstructor(new Class[] { operationsIFClass });
Object operationsIFImpl = null;
// translations for some methods only...
if (operationsIFClass.isInstance(compImpl)) {
m_logger.finer("component " + compName + " implements operations interface directly; no dynamic translator proxy used.");
operationsIFImpl = compImpl;
} else {
m_logger.finer("creating dynamic proxy to map corba interface calls to component " + compName + ".");
operationsIFImpl = compHelper.getInterfaceTranslator();
if (!Proxy.isProxyClass(operationsIFImpl.getClass()) && !(operationsIFImpl instanceof ExternalInterfaceTranslator))
m_logger.log(AcsLogLevel.NOTICE, "interface translator proxy for component " + compName + " isn't " + "the default one, and doesn't expose the default as one either. This may cause problem when invoking " + "xml-aware offshoot getters");
}
// make it a tight container (one that intercepts functional method calls)
String[] methodsExcludedFromInvocationLogging = compHelper.getComponentMethodsExcludedFromInvocationLogging();
Object poaDelegate = ContainerSealant.createContainerSealant(operationsIFClass, operationsIFImpl, compName, false, m_logger, compCL, methodsExcludedFromInvocationLogging);
// construct the POATie skeleton with operationsIFImpl as the delegate object
Servant servant = null;
try {
servant = poaTieCtor.newInstance(new Object[] { poaDelegate });
} catch (Throwable thr) {
AcsJContainerEx ex = new AcsJContainerEx(thr);
ex.setContextInfo("failed to instantiate the servant object for component " + compName + " of type " + compImpl.getClass().getName());
throw ex;
}
//
// administrate the new component
//
compAdapter = new ComponentAdapter(compName, type, exe, componentHandle, m_containerName, compImpl, m_managerProxy, sharedCdbRef, compCL, m_logger, m_acsCorba);
// to support automatic offshoot translation for xml-binded offshoots, we need to pass the dynamic adaptor
if (!operationsIFClass.isInstance(compImpl)) {
// if an external interface translator was given by the user, get the default interface translator
if (operationsIFImpl instanceof ExternalInterfaceTranslator)
operationsIFImpl = ((ExternalInterfaceTranslator) operationsIFImpl).getDefaultInterfaceTranslator();
compAdapter.setComponentXmlTranslatorProxy(operationsIFImpl);
}
// for future offshoots created by this component we must pass on the no-auto-logging info
compAdapter.setMethodsExcludedFromInvocationLogging(methodsExcludedFromInvocationLogging);
compStopWatch.reset();
compAdapter.activateComponent(servant);
LOG_CompAct_Corba_OK.log(m_logger, compName, compStopWatch.getLapTimeMillis());
// now it's time to turn off ORB logging if the new component is requesting this
if (compHelper.requiresOrbCentralLogSuppression()) {
ClientLogManager.getAcsLogManager().suppressCorbaRemoteLogging();
}
// even though the component is now an activated Corba object already,
// it won't be called yet since the maciManager will only pass around
// access information after we've returned from this activate_component method.
// Therefore it's not too late to call initialize and execute, which are
// guaranteed to be called before incoming functional calls must be expected.
// At the moment we have to call these two methods one after the other;
// if the Manager supports new calling semantics, we could separate the two
// as described in ComponentLifecycle
m_logger.fine("about to initialize component " + compName);
compStopWatch.reset();
compAdapter.initializeComponent();
compAdapter.executeComponent();
LOG_CompAct_Init_OK.log(m_logger, compName, compStopWatch.getLapTimeMillis());
// we've deferred storing the component in the map until after it's been initialized successfully
m_activeComponentMap.put(componentHandle, compAdapter);
long activTime = activationWatch.getLapTimeMillis();
m_logger.info("component " + compName + " activated and initialized in " + activTime + " ms.");
componentInfo = compAdapter.getComponentInfo();
} catch (Throwable thr) {
m_logger.log(Level.SEVERE, "Failed to activate component " + compName + ", problem was: ", thr);
if (compAdapter != null) {
try {
compAdapter.deactivateComponent();
} catch (Exception ex) {
m_logger.log(Level.FINE, ex.getMessage(), ex);
}
}
m_activeComponentMap.remove(componentHandle);
AcsJCannotActivateComponentEx ex = new AcsJCannotActivateComponentEx(thr);
throw ex.toCannotActivateComponentEx();
} finally {
// to make (possibly nested) component activations stick out in the log list
m_logger.finer(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
}
return componentInfo;
}
Aggregations