use of alma.JavaContainerError.wrappers.AcsJContainerServicesEx in project ACS by ACS-Community.
the class ContainerServicesImpl method assignUniqueEntityId.
/**
* @see alma.acs.container.ContainerServices#assignUniqueEntityId(EntityT)
*/
@Override
public void assignUniqueEntityId(EntityT entity) throws AcsJContainerServicesEx {
if (entity == null) {
AcsJBadParameterEx cause = new AcsJBadParameterEx();
cause.setParameter("entity");
cause.setParameterValue("null");
throw new AcsJContainerServicesEx(cause);
}
if (fakeUIDsForTesting) {
long localId = (new Random(System.currentTimeMillis())).nextLong();
String uid = Range.generateUID("testArchiveId", "testRangeId", localId);
entity.setEntityId(uid);
return;
}
try {
if (identifierArchive == null) {
Identifier identRaw = IdentifierHelper.narrow(getDefaultComponent("IDL:alma/xmlstore/Identifier:1.0"));
identifierArchive = getTransparentXmlWrapper(IdentifierJ.class, identRaw, IdentifierOperations.class);
}
if (uidLibrary == null) {
uidLibrary = new UIDLibrary(m_logger);
}
uidLibrary.assignUniqueEntityId(entity, identifierArchive);
} catch (Throwable thr) {
AcsJContainerServicesEx ex = new AcsJContainerServicesEx(thr);
String msg = "Failed to assign a UID to entity of type ";
if (entity.getEntityTypeName() != null) {
msg += entity.getEntityTypeName();
} else {
msg += entity.getClass().getSimpleName();
}
ex.setContextInfo(msg);
throw ex;
}
}
use of alma.JavaContainerError.wrappers.AcsJContainerServicesEx in project ACS by ACS-Community.
the class ContainerServicesImpl method getNameService.
private NamingContext getNameService() throws AcsJContainerServicesEx {
NamingContext nameService = null;
try {
org.omg.CORBA.Object nameServiceObj = m_acsManagerProxy.get_service("NameService", false);
nameService = NamingContextHelper.narrow(nameServiceObj);
} catch (AcsJmaciErrTypeEx ex) {
m_logger.log(Level.FINE, "Failed to get the reference to the NameService service", ex);
throw new AcsJContainerServicesEx(ex);
} catch (Throwable thr) {
String msg = "Unexpectedly failed to get the NameService reference!";
m_logger.log(Level.FINE, msg, thr);
AcsJContainerServicesEx ex = new AcsJContainerServicesEx(thr);
ex.setContextInfo(msg);
throw ex;
}
return nameService;
}
use of alma.JavaContainerError.wrappers.AcsJContainerServicesEx in project ACS by ACS-Community.
the class ContainerServicesImpl method createNotificationChannelSubscriber.
/**
* @TODO: once we support notification over other frameworks, check that configuration
* and instantiate some class other than NCSubscriber.
* @see alma.acs.container.ContainerServices#createNotificationChannelSubscriber(String, String)
*/
@Override
public <T> AcsEventSubscriber<T> createNotificationChannelSubscriber(String channelName, String channelNotifyServiceDomainName, Class<T> eventType) throws AcsJContainerServicesEx {
AcsEventSubscriber<T> subscriber = null;
try {
Object[] args = new Object[] { channelName, channelNotifyServiceDomainName, this, getNameService(), m_clientName, eventType };
@SuppressWarnings("unchecked") Class<AcsEventSubscriber<T>> clazz = (Class<AcsEventSubscriber<T>>) Class.forName(CLASSNAME_NC_SUBSCRIBER);
Constructor<AcsEventSubscriber<T>> constructor = clazz.getConstructor(String.class, String.class, ContainerServicesBase.class, NamingContext.class, String.class, Class.class);
subscriber = constructor.newInstance(args);
} catch (ClassNotFoundException e) {
// TODO: maybe we could prevent future NCSubscriber creation tries, since the class isn't and will not be loaded
// The same applies for the next "catch" block
m_logger.log(AcsLogLevel.ERROR, "Cannot create NC subscriber because the 'NCSubscriber' class is not present in the classpath", e);
AcsJContainerServicesEx ex = new AcsJContainerServicesEx(e);
ex.setContextInfo("'" + CLASSNAME_NC_SUBSCRIBER + "' class not present in the classpath");
throw ex;
} catch (ClassCastException e) {
m_logger.log(AcsLogLevel.ERROR, "Cannot create NC subscriber because loaded class is not of type 'AcsEventSubscriber", e);
AcsJContainerServicesEx ex = new AcsJContainerServicesEx(e);
ex.setContextInfo("'" + CLASSNAME_NC_SUBSCRIBER + "' class does not extend 'AcsEventSubscriber'");
throw ex;
} catch (Throwable e) {
if (e instanceof InvocationTargetException) {
// ctor ex
e = e.getCause();
}
m_logger.log(AcsLogLevel.ERROR, "Unexpected error while creating new AcsEventSubscriber object", e);
AcsJContainerServicesEx ex = new AcsJContainerServicesEx(e);
throw ex;
}
m_subscribers.put((channelNotifyServiceDomainName == null ? "" : channelNotifyServiceDomainName) + "/" + channelName, subscriber);
return subscriber;
}
use of alma.JavaContainerError.wrappers.AcsJContainerServicesEx in project ACS by ACS-Community.
the class ContainerServicesImpl method getComponent.
/**
* @see alma.acs.container.ContainerServices#getComponent(String)
*/
public org.omg.CORBA.Object getComponent(String curl) throws AcsJContainerServicesEx {
if (curl == null) {
AcsJBadParameterEx cause = new AcsJBadParameterEx();
cause.setParameter("curl");
cause.setParameterValue("null");
throw new AcsJContainerServicesEx(cause);
}
// check if our component has requested the other component before
org.omg.CORBA.Object stub = m_usedComponentsMap.get(curl);
if (stub != null) {
// reusing seems ok as long as there is one separate
// instance of ContainerServicesImpl for each component.
// This reuse does not cut off the manager from component access,
// since it only happens at second or further access attempts;
// the first time, the component reference is obtained through the manager
// (independently of whether the components are collocated inside the same container),
// so that the manager is aware of component dependencies.
m_logger.info("client '" + m_clientName + "' attempts to retrieve component '" + curl + "' more than once; will return existing reference.");
} else {
m_logger.fine("will retrieve remote component '" + curl + "' using ACS Manager#get_component with client handle " + getEffectiveClientHandle());
try {
stub = m_acsManagerProxy.get_component(getEffectiveClientHandle(), curl, true);
m_logger.fine("component " + curl + " retrieved successfully.");
m_usedComponentsMap.put(curl, stub);
} catch (AcsJmaciErrTypeEx ex) {
String msg = "Failed to retrieve component " + curl;
// only a low-level log because the client component is supposed to log the exception which contains all context data
m_logger.log(Level.FINE, msg, ex);
throw new AcsJContainerServicesEx(ex);
} catch (Throwable thr) {
String msg = "Failed to retrieve component " + curl + " for unexpected reasons.";
m_logger.log(Level.FINE, msg, thr);
AcsJContainerServicesEx ex = new AcsJContainerServicesEx(thr);
ex.setContextInfo(msg);
throw ex;
}
}
return stub;
}
use of alma.JavaContainerError.wrappers.AcsJContainerServicesEx in project ACS by ACS-Community.
the class ContainerServicesImpl method getDefaultComponent.
/**
* @see alma.acs.container.ContainerServices#getDefaultComponent(java.lang.String)
*/
public org.omg.CORBA.Object getDefaultComponent(String componentIDLType) throws AcsJContainerServicesEx {
if (componentIDLType == null) {
AcsJBadParameterEx cause = new AcsJBadParameterEx();
cause.setParameter("componentIDLType");
cause.setParameterValue("null");
throw new AcsJContainerServicesEx(cause);
}
ComponentInfo cInfo = null;
try {
// the call
cInfo = m_acsManagerProxy.get_default_component(getEffectiveClientHandle(), componentIDLType);
} catch (AcsJmaciErrTypeEx ex) {
String msg = "failed to retrieve default component for type " + componentIDLType;
// higher-level log should be produced by the calling client from the exception later
m_logger.log(Level.FINE, msg, ex);
throw new AcsJContainerServicesEx(ex);
} catch (Throwable thr) {
String msg = "failed to retrieve default component for type " + componentIDLType + " for unexpected reasons!";
m_logger.log(Level.FINE, msg, thr);
AcsJContainerServicesEx ex = new AcsJContainerServicesEx(thr);
ex.setContextInfo(msg);
throw ex;
}
// @todo check and remove this
if (cInfo.reference == null) {
String msg = "Default component for type '" + componentIDLType + "' could not be accessed. ";
m_logger.info(msg);
AcsJContainerServicesEx ex = new AcsJContainerServicesEx();
ex.setContextInfo(msg);
throw ex;
}
m_usedComponentsMap.put(cInfo.name, cInfo.reference);
m_componentDescriptorMap.put(cInfo.name, new ComponentDescriptor(cInfo));
return cInfo.reference;
}
Aggregations