use of alma.JavaContainerError.wrappers.AcsJContainerServicesEx in project ACS by ACS-Community.
the class ManagerContainerServices method activateOffShoot.
/**
* @see alma.acs.container.ContainerServices#activateOffShoot(org.omg.PortableServer.Servant)
*/
public <T extends Servant & OffShootOperations> OffShoot activateOffShoot(T servant) throws AcsJContainerServicesEx {
checkOffShootServant(servant);
OffShoot shoot = null;
try {
checkOffShootPOA();
org.omg.CORBA.Object actObj = null;
offshootPoa.activate_object(servant);
actObj = offshootPoa.servant_to_reference(servant);
// just to provoke an exc. if something is wrong with our new object
actObj._hash(Integer.MAX_VALUE);
logger.finer("offshoot of type '" + servant.getClass().getName() + "' activated as a CORBA object.");
shoot = OffShootHelper.narrow(actObj);
} catch (Throwable thr) {
String msg = "failed to activate offshoot object of type '" + servant.getClass().getName() + "' for client '" + getName() + "'. ";
// flatten the exception chain by one level if possible
if (thr instanceof AcsJContainerServicesEx && thr.getCause() != null) {
msg += "(" + thr.getMessage() + ")";
thr = thr.getCause();
}
logger.log(Level.FINE, msg, thr);
AcsJContainerServicesEx ex = new AcsJContainerServicesEx(thr);
throw ex;
}
return shoot;
}
use of alma.JavaContainerError.wrappers.AcsJContainerServicesEx in project ACS by ACS-Community.
the class ManagerContainerServices method createNotificationChannelPublisher.
@Override
public <T> AcsEventPublisher<T> createNotificationChannelPublisher(String channelName, String channelNotifyServiceDomainName, Class<T> eventType) throws AcsJContainerServicesEx {
AcsEventPublisher<T> publisher = null;
try {
// TODO: Matej please help, is there a more elegant way to get the naming service ref?
org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
NamingContext ncRef = NamingContextHelper.narrow(objRef);
Object[] args = new Object[] { channelName, channelNotifyServiceDomainName, this, ncRef };
// // TODO: Can we do this without the direct cast? The usual "asSubclass" is not enough
// because we don't create a subclass of Class<T> but rather of Class<U<T>>.
// Also the getGenericInterfaces / ParameterizedType trick does not work because because we don't have a
// concrete parameterized type.
Class<AcsEventPublisher<T>> clazz = (Class<AcsEventPublisher<T>>) Class.forName(CLASSNAME_NC_PUBLISHER);
Constructor<? extends AcsEventPublisher<T>> constructor = clazz.getConstructor(String.class, String.class, ContainerServicesBase.class, NamingContext.class);
publisher = constructor.newInstance(args);
} catch (ClassNotFoundException e) {
// TODO: maybe we could prevent future NCPublisher creation tries, since the class isn't and will not be loaded
// The same applies for the next "catch" block
logger.log(AcsLogLevel.ERROR, "Cannot create NC publisher because the 'NCPublisher' class is not present in the classpath", e);
AcsJContainerServicesEx ex = new AcsJContainerServicesEx(e);
ex.setContextInfo("'" + CLASSNAME_NC_PUBLISHER + "' class not present in the classpath");
throw ex;
} catch (ClassCastException e) {
logger.log(AcsLogLevel.ERROR, "Cannot create NC publisher because loaded class '" + CLASSNAME_NC_PUBLISHER + "' is not of type 'AcsEventPublisher", e);
AcsJContainerServicesEx ex = new AcsJContainerServicesEx(e);
ex.setContextInfo("'" + CLASSNAME_NC_PUBLISHER + "' class does not extend 'AcsEventPublisher'");
throw ex;
} catch (Throwable e) {
logger.log(AcsLogLevel.ERROR, "Unexpected error while creating new AcsEventPublisher object", e);
AcsJContainerServicesEx ex = new AcsJContainerServicesEx(e);
throw ex;
}
return publisher;
}
use of alma.JavaContainerError.wrappers.AcsJContainerServicesEx in project ACS by ACS-Community.
the class ManagerContainerServices method checkOffShootServant.
/**
* @param cbServant
* @throws ContainerException
*/
private void checkOffShootServant(Servant servant) throws AcsJContainerServicesEx {
if (servant == null) {
AcsJBadParameterEx cause = new AcsJBadParameterEx();
cause.setParameter("servant");
cause.setParameterValue("null");
throw new AcsJContainerServicesEx(cause);
}
if (!(servant instanceof OffShootOperations)) {
String msg = "invalid offshoot servant provided. Must implement " + OffShootOperations.class.getName();
logger.fine(msg);
AcsJContainerServicesEx ex = new AcsJContainerServicesEx();
ex.setContextInfo(msg);
throw ex;
}
}
use of alma.JavaContainerError.wrappers.AcsJContainerServicesEx in project ACS by ACS-Community.
the class FileReaderCollectorImpl method initialize.
@Override
public void initialize(ContainerServices inContainerServices) throws ComponentLifecycleException {
super.initialize(inContainerServices);
Controller controller;
try {
controller = ControllerHelper.narrow(m_containerServices.getComponent("ARCHIVE/TMCDB/MONITOR_CONTROL"));
controller.registerCollector(name());
} catch (AcsJContainerServicesEx ex) {
throw new ComponentLifecycleException(ex);
} catch (CollectorRegistrationFailedEx ex) {
throw new ComponentLifecycleException(ex);
}
}
use of alma.JavaContainerError.wrappers.AcsJContainerServicesEx in project ACS by ACS-Community.
the class ComponentAccessUtil method getDynamicComponent.
/**
* Returns the cached reference or the component retrieved from the container services
* @param <T> The IDL-derived component interface
* @param compSpec
* @param idlOpInterface
* @return
* @throws AcsJContainerServicesEx
*/
public <T extends ACSComponentOperations> T getDynamicComponent(ComponentSpec compSpec, Class<T> idlOpInterface) throws AcsJContainerServicesEx {
T comp = null;
boolean foundInCache = false;
boolean mustActivateComp = false;
CompRefHelper compRefHelper = null;
synchronized (compName2Comp) {
// try the cache first
compRefHelper = compName2Comp.get(compSpec.component_name);
if (compRefHelper == null) {
mustActivateComp = true;
compRefHelper = new CompRefHelper();
compName2Comp.put(compSpec.component_name, compRefHelper);
} else {
if (compRefHelper.compRef != null) {
if (compRefHelper.isReleasing) {
AcsJContainerServicesEx ex = new AcsJContainerServicesEx();
ex.setContextInfo("Component '" + compSpec.component_name + "' is being released and thus cannot be activated.");
throw ex;
}
foundInCache = true;
comp = idlOpInterface.cast(compRefHelper.compRef);
}
}
}
try {
if (!foundInCache) {
if (mustActivateComp) {
comp = getDynamicComponentFromContainerServices(compSpec, idlOpInterface);
// this will free other threads waiting for the same comp.
compRefHelper.setCompRef(comp);
} else {
// wait if another thread is already activating this comp
boolean waitOK = false;
try {
waitOK = compRefHelper.awaitCompActivation(5, TimeUnit.MINUTES);
} catch (InterruptedException ex) {
// just leave waitOK = false
}
if (!waitOK) {
AcsJContainerServicesEx ex = new AcsJContainerServicesEx();
ex.setContextInfo("Timed out or got interrupted while waiting for activation of component '" + compSpec.component_name + "'.");
throw ex;
}
}
}
return comp;
} finally {
logger.log(AcsLogLevel.DEBUG, "Retrieved component '" + compSpec.component_name + "' from " + (foundInCache ? "cache." : "container services."));
}
}
Aggregations