use of com.cosylab.acs.maci.ComponentInfo in project ACS by ACS-Community.
the class ManagerImplTest method testComponentInfo.
public void testComponentInfo() {
/// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if (false) {
try {
//TODO get ComponentInfo
manager.getComponentInfo(0, null, null, null, false);
manager.getComponentInfo(Integer.MAX_VALUE, null, null, null, false);
manager.getComponentInfo(dummyHandle, null, null, null, false);
manager.getComponentInfo(dummyHandle, null, "non-null", null, true);
manager.getComponentInfo(dummyHandle, null, null, "non-null", true);
manager.getComponentInfo(dummyHandle, new int[0], null, null, false);
manager.getComponentInfo(dummyHandle, new int[0], "non-null", null, true);
manager.getComponentInfo(dummyHandle, new int[0], null, "non-null", false);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
try {
Administrator client = new TestAdministrator(clientName);
ClientInfo info = manager.login(client);
manager.getComponentInfo(info.getHandle(), new int[0], "*MOUNT*", "*", false);
manager.logout(info.getHandle());
} catch (Throwable e) {
e.printStackTrace();
fail(e.getMessage());
}
TestContainer container = new TestContainer("Container");
Map supportedComponents = new HashMap();
Component mount1COB = new TestComponent("MOUNT1");
supportedComponents.put("MOUNT1", mount1COB);
Component mount4COB = new TestComponent("MOUNT4");
supportedComponents.put("MOUNT4", mount4COB);
container.setSupportedComponents(supportedComponents);
ClientInfo containerInfo = null;
try {
containerInfo = manager.login(container);
} catch (AcsJNoPermissionEx e1) {
fail("No permission");
}
try {
Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
try {
Administrator client = new TestAdministrator(clientName);
ClientInfo info = manager.login(client);
ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "MOUNT1", "*", false);
assertEquals(1, infos.length);
} catch (Throwable e) {
e.printStackTrace();
fail(e.getMessage());
}
try {
manager.logout(containerInfo.getHandle());
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
use of com.cosylab.acs.maci.ComponentInfo in project ACS by ACS-Community.
the class ManagerImpl method internalNoSyncRequestComponentPhase2.
private ComponentInfo internalNoSyncRequestComponentPhase2(int requestor, String name, String type, String code, String containerName, int keepAliveTime, StatusHolder status, AcsJCannotGetComponentEx bcex, boolean isOtherDomainComponent, boolean isDynamicComponent, int h, boolean reactivate, ComponentInfo componentInfo, Container container, ContainerInfo containerInfo, long executionId, long activationTime, boolean timeoutError) throws AcsJCannotGetComponentEx {
// remove component from client component list, will be added later (first lots of checks has to be done)
if ((requestor & TYPE_MASK) == COMPONENT_MASK) {
removeComponentOwner(h | COMPONENT_MASK, requestor);
}
// remove from pending activation list
synchronized (pendingActivations) {
pendingActivations.remove(name);
}
// failed to activate
if (componentInfo == null || componentInfo.getHandle() == 0 || componentInfo.getComponent() == null) {
if (bcex == null)
logger.log(Level.SEVERE, "Failed to activate component '" + name + "' (" + HandleHelper.toString(h | COMPONENT_MASK) + ").");
else
bcex.setReason("Failed to activate component '" + name + "' (" + HandleHelper.toString(h | COMPONENT_MASK) + ").");
componentsLock.lock();
try {
// !!! ACID 3
if (!reactivate)
executeCommand(new ComponentCommandDeallocate(h, h | COMPONENT_MASK, timeoutError ? WhyUnloadedReason.TIMEOUT : WhyUnloadedReason.REMOVED, true));
//components.deallocate(h, true);
} finally {
componentsLock.unlock();
}
status.setStatus(ComponentStatus.COMPONENT_NOT_ACTIVATED);
if (bcex == null)
return null;
else
throw bcex;
}
// log info
logger.log(Level.INFO, "Component '" + name + "' (" + HandleHelper.toString(h | COMPONENT_MASK) + ") activated successfully.");
//
if (!isOtherDomainComponent && !componentInfo.getComponent().doesImplement(type)) {
// just output SEVERE message
logger.log(Level.SEVERE, "Activated component '" + name + "' does not implement specified type '" + type + "'.");
}
// component info (to get type and code, container - prefix name)
if (isOtherDomainComponent) {
// @todo MF tmp (for testing)
componentInfo.setHandle(h | COMPONENT_MASK);
componentInfo.setClients(new IntArray());
componentInfo.setComponents(new IntArray(0));
componentInfo.setContainer(0);
// set variables
type = componentInfo.getType();
code = componentInfo.getCode();
}
int[] clients;
componentsLock.lock();
try {
//
if (componentInfo.getHandle() != (h | COMPONENT_MASK)) {
// container returned different handle
// (it seems it has already activated this Component)
// check if we can accept it
int componentHandle = componentInfo.getHandle() & HANDLE_MASK;
if (components.isAllocated(componentHandle)) {
// cancel preallocation
if (!reactivate)
executeCommand(new ComponentCommandDeallocate(h, componentInfo.getHandle(), WhyUnloadedReason.REMOVED, true));
//components.deallocate(h, true);
bcex = new AcsJCannotGetComponentEx();
bcex.setReason("Container '" + containerName + "' returned another '" + name + "' component handle than given, failed to fix handle since returned handle is already allocated.");
// log this anyway, since it's an error of a global nature
logger.log(Level.SEVERE, "Container '" + containerName + "' returned another '" + name + "' component handle than given, failed to fix handle since returned handle is already allocated.", bcex);
// component is activated, but cannot be managed by the Manager
status.setStatus(ComponentStatus.COMPONENT_ACTIVATED);
throw bcex;
} else {
// handle is free, relocate handle
ComponentInfo existingData = null;
// deallocate old
if (!reactivate)
executeCommand(new ComponentCommandDeallocate(h, componentInfo.getHandle(), WhyUnloadedReason.REPLACED, true));
else //components.deallocate(h, true);
{
// !!! ACID 3
existingData = (ComponentInfo) components.get(h);
executeCommand(new ComponentCommandDeallocate(h, componentInfo.getHandle(), WhyUnloadedReason.REPLACED));
//components.deallocate(h);
}
// !!! ACID 3
// preallocate new
Integer objHandle = (Integer) executeCommand(new ComponentCommandAllocateHandle(componentHandle, true));
//h = components.allocate(componentHandle, true);
if (objHandle == null || (h = objHandle.intValue()) == 0) {
// failed to allocate new
bcex = new AcsJCannotGetComponentEx();
bcex.setReason("Container '" + containerName + "' returned another '" + name + "' component handle than given, failed to fix handle due to handle relocation failure.");
// log this anyway, since it's an error of a global nature
logger.log(Level.SEVERE, "Container '" + containerName + "' returned another '" + name + "' component handle than given, failed to fix handle due to handle relocation failure.", bcex);
// Component is activated, but cannot be managed by the Manager
status.setStatus(ComponentStatus.COMPONENT_ACTIVATED);
throw bcex;
} else // !!! ACID 3
if (existingData != null)
executeCommand(new ComponentCommandSet(h, existingData));
//components.set(h, existingData);
logger.log(Level.WARNING, "Container '" + containerName + "' returned another '" + name + "' component handle than given, handle fixed.");
}
}
//
// pre-store data
//
ComponentInfo existingData = (ComponentInfo) components.get(h);
// create a new ComponentInfo - do not trust containers
ComponentInfo data = new ComponentInfo(componentInfo.getHandle(), name, type, code, componentInfo.getComponent());
if (existingData != null) {
data.setClients(existingData.getClients());
data.setComponents(existingData.getComponents());
}
if (requestor != 0)
if (// hierarchical components need this check
!data.getClients().contains(requestor))
data.getClients().add(requestor);
if (keepAliveTime <= RELEASE_NEVER)
if (// make component immortal
!data.getClients().contains(this.getHandle()))
data.getClients().add(this.getHandle());
// remember keep alive time
data.setKeepAliveTime(keepAliveTime);
if (isOtherDomainComponent) {
data.setContainer(0);
data.setContainerName(componentInfo.getContainerName());
} else {
data.setContainer(containerInfo.getHandle());
data.setContainerName(containerInfo.getName());
}
data.setAccessRights(0);
data.setInterfaces(componentInfo.getInterfaces());
// mark as dynamic component and store its container
if (isDynamicComponent) {
data.setDynamic(true);
data.setDynamicContainerName(containerName);
}
// !!! ACID
executeCommand(new ComponentCommandSet(h, data));
// acknowledge allocation
if (!reactivate)
// !!! ACID 2
executeCommand(new ComponentCommandAckAlloc(h));
//components.ackAllocation(h);
componentInfo = data;
clients = componentInfo.getClients().toArray();
} finally {
componentsLock.unlock();
}
if (!isOtherDomainComponent) {
// add component to client component list to allow dependency checks
if ((requestor & TYPE_MASK) == COMPONENT_MASK)
addComponentOwner(componentInfo.getHandle(), requestor);
//
// call construct
//
boolean constructed = false;
try {
componentInfo.getComponent().construct();
constructed = true;
} catch (Throwable ex) {
bcex = new AcsJCannotGetComponentEx(ex);
bcex.setReason("Failed to construct component '" + name + "', exception caught when invoking 'construct()' method.");
}
// remove component from client component list, will be added later
if ((requestor & TYPE_MASK) == COMPONENT_MASK)
removeComponentOwner(componentInfo.getHandle(), requestor);
if (!constructed) {
// release Component
componentsLock.lock();
try {
// !!! ACID 3
if (!reactivate)
executeCommand(new ComponentCommandDeallocate(h, componentInfo.getHandle(), WhyUnloadedReason.REMOVED));
// deactivate
try {
container.deactivate_component(componentInfo.getHandle());
} catch (Exception ex) {
bcex = new AcsJCannotGetComponentEx(ex);
bcex.setReason("Failed to deactivate component '" + name + "' on container '" + containerName + "'.");
}
status.setStatus(ComponentStatus.COMPONENT_NOT_ACTIVATED);
throw bcex;
} finally {
componentsLock.unlock();
}
}
}
// add component to client component list
if (requestor != this.getHandle() && requestor != 0)
addComponentOwner(componentInfo.getHandle(), requestor);
// add component to container component list
if (!isOtherDomainComponent)
synchronized (containerInfo.getComponents()) {
if (!containerInfo.getComponents().contains(componentInfo.getHandle()))
executeCommand(new ContainerInfoCommandComponentAdd(containerInfo.getHandle() & HANDLE_MASK, componentInfo.getHandle()));
//containerInfo.getComponents().add(componentInfo.getHandle());
}
// remove component from unavailable list
if (reactivate) {
synchronized (unavailableComponents) {
executeCommand(new UnavailableComponentCommandRemove(name));
//unavailableComponents.remove(name);
}
}
//
if (!isOtherDomainComponent)
notifyComponentActivated(componentInfo, activationTime, executionId);
//
if (reactivate) {
notifyComponentAvailable(requestor, clients, new ComponentInfo[] { componentInfo });
}
//
// notify administrators about the activation
//
notifyComponentRequested(new int[] { requestor }, new int[] { componentInfo.getHandle() }, activationTime);
if (reactivate)
logger.log(Level.FINE, "Component '" + name + "' (" + HandleHelper.toString(componentInfo.getHandle()) + ") reactivated.");
else
logger.log(Level.FINE, "Component '" + name + "' (" + HandleHelper.toString(componentInfo.getHandle()) + ") activated.");
// notify about the change (only this-domain container which activated the component)...
if (containerInfo != null)
topologySortManager.notifyTopologyChange(containerInfo.getHandle());
status.setStatus(ComponentStatus.COMPONENT_ACTIVATED);
return componentInfo;
}
use of com.cosylab.acs.maci.ComponentInfo in project ACS by ACS-Community.
the class ManagerImpl method internalRequestComponent.
/**
* Internal method for requesting components.
* @param requestor requestor of the component.
* @param curl curl of the component to be requested.
* @param status status of the component.
* @param activate <code>true</code> if component has to be activated
* @return component requested component.
*/
private Component internalRequestComponent(int requestor, URI curl, StatusHolder status, boolean activate) throws AcsJCannotGetComponentEx {
// extract unique name
String name = extractName(curl);
try {
checkCyclicDependency(requestor, name);
} catch (AcsJCyclicDependencyDetectedEx e) {
AcsJCannotGetComponentEx cgce = new AcsJCannotGetComponentEx(e);
cgce.setCURL(name);
throw cgce;
}
// try to acquire lock
long lockTimeoutMillis = getLockTimeout();
String lockNotAcquiredCause = acquireSynchronizationObject(name, lockTimeoutMillis, "request component " + name);
if (lockNotAcquiredCause == null) {
boolean releaseRWLock = true;
try {
// try to acquire activation readers lock first
// NOTE: the locks are NOT reentrant
activationPendingRWLock.readLock().lock();
// Let AcsJCannotGetComponentEx fly up
ComponentInfo componentInfo = null;
try {
componentInfo = internalNoSyncRequestComponent(requestor, name, null, null, null, RELEASE_TIME_UNDEFINED, status, activate);
} catch (AcsJComponentSpecIncompatibleWithActiveComponentEx ciwace) {
status.setStatus(ComponentStatus.COMPONENT_NOT_ACTIVATED);
AcsJCannotGetComponentEx cgce = new AcsJCannotGetComponentEx(ciwace);
cgce.setCURL(name);
throw cgce;
}
if (componentInfo != null) {
return componentInfo.getComponent();
} else {
return null;
}
} finally {
if (releaseRWLock) {
activationPendingRWLock.readLock().unlock();
}
releaseSynchronizationObject(name);
}
} else {
String msg = "Failed to obtain synchronization lock for component '" + name + "' within '" + lockTimeoutMillis + "' ms, possible deadlock; locked to '" + lockNotAcquiredCause + "'.";
logger.fine(msg);
NoResourcesException nre = new NoResourcesException(msg);
throw nre;
}
}
use of com.cosylab.acs.maci.ComponentInfo in project ACS by ACS-Community.
the class ManagerImpl method internalNoSyncRequestComponent.
/**
* Internal method for requesting components (non sync).
* @param requestor requestor of the component.
* @param name name of component to be requested, non-<code>null</code>.
* @param type type of component to be requested; if <code>null</code> CDB will be queried.
* @param code code of component to be requested; if <code>null</code> CDB will be queried.
* @param containerName container name of component to be requested; if <code>null</code> CDB will be queried.
* @param status returned completion status of the request.
* @param activate <code>true</code> if component has to be activated
* @return componentInfo <code>ComponentInfo</code> of requested component.
*/
private ComponentInfo internalNoSyncRequestComponent(int requestor, String name, String type, String code, String containerName, int keepAliveTime, StatusHolder status, boolean activate) throws AcsJCannotGetComponentEx, AcsJComponentSpecIncompatibleWithActiveComponentEx {
AcsJCannotGetComponentEx bcex = null;
if (name == null) {
bcex = new AcsJCannotGetComponentEx();
bcex.setReason("Cannot activate component with NULL name.");
throw bcex;
}
if (status == null) {
bcex = new AcsJCannotGetComponentEx();
bcex.setReason("Component " + name + " has NULL status.");
throw bcex;
}
boolean isOtherDomainComponent = name.startsWith(CURL_URI_SCHEMA);
boolean isDynamicComponent = isOtherDomainComponent ? false : (type != null || code != null || containerName != null);
//
// check if component is already activated
//
int h;
// if true, component with handle h will be reactivated
boolean reactivate = false;
ComponentInfo componentInfo = null;
componentsLock.lock();
try {
h = components.first();
while (h != 0) {
componentInfo = (ComponentInfo) components.get(h);
if (componentInfo.getName().equals(name)) {
// check if component is unavailable
synchronized (unavailableComponents) {
if (unavailableComponents.containsKey(name)) {
// try to reactivate, possible component reallocation
reactivate = true;
}
}
// check for consistency
ContainerInfo containerInfo = getContainerInfo(componentInfo.getContainer());
if ((type != null && !componentInfo.getType().equals(type)) || (code != null && componentInfo.getCode() != null && !componentInfo.getCode().equals(code)) || (!reactivate && containerInfo != null && containerName != null && !containerInfo.getName().equals(containerName))) {
AcsJComponentSpecIncompatibleWithActiveComponentEx ciwace = new AcsJComponentSpecIncompatibleWithActiveComponentEx();
ciwace.setCURL(componentInfo.getName());
ciwace.setComponentType(componentInfo.getType());
ciwace.setComponentCode(componentInfo.getCode() != null ? componentInfo.getCode() : "<unknown>");
ciwace.setContainerName(containerInfo != null ? containerInfo.getName() : "<none>");
throw ciwace;
}
if (activate) {
// bail out and reactivate
if (reactivate)
break;
// add client/component as an owner (if requestor is not 'reactivation')
if (requestor != 0) {
// !!! ACID
if (!componentInfo.getClients().contains(requestor))
executeCommand(new ComponentCommandClientAdd(componentInfo.getHandle() & HANDLE_MASK, requestor));
//componentInfo.getClients().add(requestor);
}
// add component to client component list (if requestor is not manager or 'reactivation')
if (requestor != this.getHandle() && requestor != 0)
addComponentOwner(componentInfo.getHandle(), requestor);
// inform administrators about component request
notifyComponentRequested(new int[] { requestor }, new int[] { componentInfo.getHandle() }, System.currentTimeMillis());
// on complete system shutdown sort will be done anyway
if ((requestor & TYPE_MASK) == COMPONENT_MASK) {
ComponentInfo requestorComponentInfo = getComponentInfo(requestor);
if (requestorComponentInfo != null && requestorComponentInfo.getContainerName() != null && requestorComponentInfo.getContainerName().equals(componentInfo.getContainerName()))
topologySortManager.notifyTopologyChange(componentInfo.getContainer());
}
// return info
status.setStatus(ComponentStatus.COMPONENT_ACTIVATED);
return componentInfo;
} else {
if (reactivate)
status.setStatus(ComponentStatus.COMPONENT_NOT_ACTIVATED);
else
status.setStatus(ComponentStatus.COMPONENT_ACTIVATED);
return componentInfo;
}
}
h = components.next(h);
}
} finally {
componentsLock.unlock();
}
// and do not touch CDB
if (reactivate && componentInfo.isDynamic()) {
if (componentInfo.getType() == null || componentInfo.getCode() == null || componentInfo.getDynamicContainerName() == null) {
// failed
bcex = new AcsJCannotGetComponentEx();
bcex.setReason("Failed to reactivate dynamic component '" + componentInfo + "'.");
status.setStatus(ComponentStatus.COMPONENT_DOES_NO_EXIST);
throw bcex;
} else {
// reread info
type = componentInfo.getType();
code = componentInfo.getCode();
containerName = componentInfo.getDynamicContainerName();
keepAliveTime = componentInfo.getKeepAliveTime();
}
} else // is CDB lookup needed
if (!isOtherDomainComponent && (type == null || code == null || containerName == null)) {
//
// read component info from CDB / remote directory lookup
//
DAOProxy dao = getComponentsDAOProxy();
if (dao == null || readStringCharacteristics(dao, name, true) == null) {
// component with this name does not exists,
// make a remote directory lookup
Object ref = lookup(name, null);
if (ref != null) {
// found
status.setStatus(ComponentStatus.COMPONENT_ACTIVATED);
return new ComponentInfo(0, name, null, null, new ServiceComponent(ref));
} else {
// not found
bcex = new AcsJCannotGetComponentEx();
bcex.setReason("Component " + name + " not found in CDB.");
status.setStatus(ComponentStatus.COMPONENT_DOES_NO_EXIST);
throw bcex;
}
}
if (code == null) {
code = readStringCharacteristics(dao, name + "/Code");
if (code == null) {
bcex = new AcsJCannotGetComponentEx();
bcex.setReason("Misconfigured CDB, there is no code of component '" + name + "' defined.");
status.setStatus(ComponentStatus.COMPONENT_DOES_NO_EXIST);
throw bcex;
}
}
if (type == null) {
type = readStringCharacteristics(dao, name + "/Type");
if (type == null) {
bcex = new AcsJCannotGetComponentEx();
bcex.setReason("Misconfigured CDB, there is no type of component '" + name + "' defined.");
status.setStatus(ComponentStatus.COMPONENT_DOES_NO_EXIST);
throw bcex;
}
}
if (containerName == null) {
containerName = readStringCharacteristics(dao, name + "/Container");
if (containerName == null) {
bcex = new AcsJCannotGetComponentEx();
bcex.setReason("Misconfigured CDB, there is no container of component '" + name + "' defined.");
status.setStatus(ComponentStatus.COMPONENT_DOES_NO_EXIST);
throw bcex;
}
}
if (keepAliveTime == RELEASE_TIME_UNDEFINED) {
// defaults to 0 == RELEASE_IMMEDIATELY
keepAliveTime = readLongCharacteristics(dao, name + "/KeepAliveTime", RELEASE_IMMEDIATELY, true);
}
}
// we have keepAlive missing, try to get it
if (keepAliveTime == RELEASE_TIME_UNDEFINED) {
DAOProxy dao = getComponentsDAOProxy();
if (dao != null) {
// defaults to 0 == RELEASE_IMMEDIATELY
keepAliveTime = readLongCharacteristics(dao, name + "/KeepAliveTime", RELEASE_IMMEDIATELY, true);
} else {
// this is a case where all data for dynamic component is specified and there is not entry in CDB
keepAliveTime = RELEASE_IMMEDIATELY;
}
}
// read impl. language.
DAOProxy dao = getComponentsDAOProxy();
String componentImplLang = null;
if (dao != null) {
// silent read
componentImplLang = readStringCharacteristics(dao, name + "/ImplLang", true);
}
// if requestor did not request activation we are finished
if (!activate) {
status.setStatus(ComponentStatus.COMPONENT_NOT_ACTIVATED);
return null;
}
/****************** component activation ******************/
//
// get container/remote manager
//
Container container = null;
ContainerInfo containerInfo = null;
Manager remoteManager = null;
if (isOtherDomainComponent) {
// @todo MF do the login?
try {
String domainName = CURLHelper.createURI(name).getAuthority();
remoteManager = getManagerForDomain(domainName);
if (remoteManager == null) {
bcex = new AcsJCannotGetComponentEx();
bcex.setReason("Failed to obtain manager for domain '" + domainName + "'.");
throw bcex;
}
} catch (Throwable th) {
bcex = new AcsJCannotGetComponentEx(th);
bcex.setReason("Failed to obtain non-local manager required by component '" + name + "'.'");
status.setStatus(ComponentStatus.COMPONENT_NOT_ACTIVATED);
throw bcex;
}
} else {
// search for container by its name
containerInfo = getContainerInfo(containerName);
// try to start-up container
if (containerInfo == null)
containerInfo = startUpContainer(containerName);
// check state and get container
if (containerInfo != null) {
checkContainerShutdownState(containerInfo);
container = containerInfo.getContainer();
}
// required container is not logged in
if (container == null) {
bcex = new AcsJCannotGetComponentEx();
bcex.setReason("Container '" + containerName + "' required by component '" + name + "' is not logged in.");
status.setStatus(ComponentStatus.COMPONENT_NOT_ACTIVATED);
throw bcex;
}
}
// check container vs component ImplLang
ImplLang containerImplLang = containerInfo.getImplLang();
if (containerImplLang != null && containerImplLang != ImplLang.not_specified) {
if (componentImplLang != null && ImplLang.fromString(componentImplLang) != containerImplLang) {
AcsJCannotGetComponentEx af = new AcsJCannotGetComponentEx();
af.setReason("Component and container implementation language do not match (" + componentImplLang + " != " + containerImplLang.name() + ")");
throw af;
}
}
//
// get handle
//
// obtain handle
componentsLock.lock();
try {
// only preallocate (if necessary)
if (!reactivate) {
// !!! ACID 2
Integer objHandle = (Integer) executeCommand(new ComponentCommandPreallocate());
h = (objHandle == null) ? 0 : objHandle.intValue();
//h = components.preallocate();
}
// failed to obtain handle
if (h == 0) {
AcsJCannotGetComponentEx af = new AcsJCannotGetComponentEx();
af.setReason("Preallocation of new handle failed, too many registered components.");
throw af;
}
// create temporary ComponentInfo - to allow hierarchical components
if (!reactivate) {
ComponentInfo data = new ComponentInfo(h | COMPONENT_MASK, name, type, code, null);
data.setKeepAliveTime(keepAliveTime);
// !!! ACID
executeCommand(new ComponentCommandSet(h, data));
// add to pending activation list
synchronized (pendingActivations) {
pendingActivations.put(name, data);
}
// add component to client component list to allow dependency checks
if ((requestor & TYPE_MASK) == COMPONENT_MASK)
addComponentOwner(data.getHandle(), requestor);
}
} finally {
componentsLock.unlock();
}
//
// invoke get_component
//
componentInfo = null;
long executionId = 0;
long activationTime = 0;
boolean timeoutError = false;
if (isOtherDomainComponent) {
try {
URI curlName = CURLHelper.createURI(name);
StatusHolder statusHolder = new StatusHolder();
// @todo MF tmp (handle)
remoteManager.getComponent(INTERDOMAIN_MANAGER_HANDLE, curlName, true, statusHolder);
activationTime = System.currentTimeMillis();
if (statusHolder.getStatus() == ComponentStatus.COMPONENT_ACTIVATED) {
// local name to be used
String localName = curlName.getPath();
if (localName.charAt(0) == '/')
localName = localName.substring(1);
/// @TODO MF tmp (handle)
ComponentInfo[] infos = remoteManager.getComponentInfo(INTERDOMAIN_MANAGER_HANDLE, new int[0], localName, "*", true);
if (infos != null && infos.length == 1) {
componentInfo = infos[0];
// fix container name
componentInfo.setContainerName(CURL_URI_SCHEMA + curlName.getAuthority() + "/" + componentInfo.getContainerName());
}
//else
// throw new RemoteException("Failed to obtain component info for '"+name+"' from remote manager.");
}
//else
// throw new RemoteException("Failed to obtain component '"+name+"' from remote manager, status: " + statusHolder.getStatus() + ".");
} catch (Throwable ex) {
bcex = new AcsJCannotGetComponentEx(ex);
bcex.setReason("Failed to obtain component '" + name + "' from remote manager.");
timeoutError = (ex instanceof TimeoutRemoteException);
}
} else {
//
// invoke get_component on container
//
// log info
String handleReadable = HandleHelper.toString(h | COMPONENT_MASK);
logger.log(Level.INFO, "Activating component '" + name + "' (" + handleReadable + ") on container '" + containerInfo.getName() + "'.");
boolean callSyncActivate = System.getProperties().containsKey(NAME_SYNC_ACTIVATE);
if (callSyncActivate) {
// sync
try {
executionId = generateExecutionId();
activationTime = System.currentTimeMillis();
componentInfo = container.activate_component(h | COMPONENT_MASK, executionId, name, code, type);
} catch (Throwable ex) {
bcex = new AcsJCannotGetComponentEx(ex);
bcex.setReason("Failed to activate component '" + name + "' on container '" + containerName + "'.");
timeoutError = (ex instanceof TimeoutRemoteException);
}
} else {
// async
try {
executionId = generateExecutionId();
activationTime = System.currentTimeMillis();
ComponentInfoCompletionCallbackImpl callback = new ComponentInfoCompletionCallbackImpl(requestor, name, type, code, containerName, keepAliveTime, status, isOtherDomainComponent, isDynamicComponent, h, reactivate, container, containerInfo, executionId, activationTime);
addPendingContainerAsyncRequest(containerName, callback);
try {
container.activate_component_async(h | COMPONENT_MASK, executionId, name, code, type, callback);
} catch (Throwable t) {
// failed call, remove async request from the list
removePendingContainerAsyncRequest(containerName, callback);
throw t;
}
logger.log(AcsLogLevel.DELOUSE, "Asynchronous activation of component '" + name + "' (" + handleReadable + ") is running on container '" + containerInfo.getName() + "'.");
ComponentInfo ret;
try {
ret = callback.waitUntilActivated(getLockTimeout());
} catch (Throwable t) {
// failed call (most likely timeout), remove async request from the list
removePendingContainerAsyncRequest(containerName, callback);
throw t;
}
logger.log(AcsLogLevel.DELOUSE, "Asynchronous activation of component '" + name + "' (" + handleReadable + ") has finished on container '" + containerInfo.getName() + "'.");
return ret;
} catch (Throwable ex) {
bcex = new AcsJCannotGetComponentEx(ex);
bcex.setReason("Failed to activate component '" + name + "' on container '" + containerName + "'.");
throw bcex;
}
}
}
// call this immediately if bcex != null or sync call
return internalNoSyncRequestComponentPhase2(requestor, name, type, code, containerName, keepAliveTime, status, bcex, isOtherDomainComponent, isDynamicComponent, h, reactivate, componentInfo, container, containerInfo, executionId, activationTime, timeoutError);
}
use of com.cosylab.acs.maci.ComponentInfo in project ACS by ACS-Community.
the class ManagerImpl method internalReleaseComponent.
/**
* Internal method for releasing components.
*
* @param owner owner of the component.
* @param h handle of the component to be released.
* @param force force deactivate, if still has owners then component will be made unavailable.
* @return Number of clients that are still using the component after the operation completed.
*/
private ReleaseComponentResult internalReleaseComponent(int owner, int h, boolean force) throws AcsJNoPermissionEx, AcsJBadParameterEx {
// extract name
String name = null;
componentsLock.lock();
try {
int handle = h & HANDLE_MASK;
ComponentInfo componentInfo = null;
if (components.isAllocated(handle))
componentInfo = (ComponentInfo) components.get(handle);
if (componentInfo == null) {
// invalid Component handle
AcsJBadParameterEx ex = new AcsJBadParameterEx();
ex.setParameter("componentInfo");
ex.setParameterValue("null");
throw ex;
}
if (componentInfo.getHandle() != h) {
// invalid Component handle
AcsJBadParameterEx ex = new AcsJBadParameterEx();
ex.setParameter("h");
throw ex;
}
name = componentInfo.getName();
} finally {
componentsLock.unlock();
}
// try to acquire lock
String lockNotAcquiredCause = acquireSynchronizationObject(name, lockTimeout, "release component " + name);
if (lockNotAcquiredCause == null) {
boolean releaseRWLock = true;
try {
// try to acquire activation readers lock first
// NOTE: the locks are NOT reentrant
activationPendingRWLock.readLock().lock();
return internalNoSyncReleaseComponent(owner, h, force);
} finally {
if (releaseRWLock)
activationPendingRWLock.readLock().unlock();
releaseSynchronizationObject(name);
}
} else {
NoResourcesException nre = new NoResourcesException("Failed to obtain synchronization lock for component '" + name + "', possible deadlock; locked to '" + lockNotAcquiredCause + "'.");
throw nre;
}
}
Aggregations