use of alma.ACSErrTypeCommon.wrappers.AcsJUnexpectedExceptionEx in project ACS by ACS-Community.
the class EventModel method resolveNotificationChannel.
/**
* Resolves a notification channel in the naming service.
*
* @return Reference to the event channel specified by channelName.
* @param bindingName
* Name of the event channel and trailing domain name, as the NC is registered with the CORBA Naming Service
* @throws AcsJException
* Standard ACS Java exception.
*/
protected EventChannel resolveNotificationChannel(String bindingName) throws AcsJException {
EventChannel retValue = null;
String nameServiceKind = alma.acscommon.NC_KIND.value;
//m_logger.info("Will call 'nctx.resolve' for binding='" + bindingName + "', kind='" + nameServiceKind + "'.");
try {
NameComponent[] t_NameSequence = { new NameComponent(bindingName, nameServiceKind) };
retValue = EventChannelHelper.narrow(nctx.resolve(t_NameSequence));
} catch (OBJECT_NOT_EXIST ex) {
m_logger.severe("The NC '" + bindingName + "' no longer exists, probably because its notify service was restarted. The naming service still lists this NC.");
throw new AcsJUnexpectedExceptionEx(ex);
} catch (org.omg.CosNaming.NamingContextPackage.NotFound e) {
// No other suppliers have created the channel yet
m_logger.info("The '" + bindingName + "' channel has not been created yet.");
throw new AcsJUnexpectedExceptionEx(e);
} catch (org.omg.CosNaming.NamingContextPackage.CannotProceed e) {
// Think there is virtually no chance of this every happening but...
throw new AcsJUnexpectedExceptionEx(e);
} catch (org.omg.CosNaming.NamingContextPackage.InvalidName e) {
// Think there is virtually no chance of this every happening but...
throw new AcsJUnexpectedExceptionEx(e);
}
return retValue;
}
use of alma.ACSErrTypeCommon.wrappers.AcsJUnexpectedExceptionEx in project ACS by ACS-Community.
the class AcsCorba method getPOAForOffshoots.
/**
* Creates (or reuses) the non-persistent POA for offshoot objects as a child of the given POA.
* In spite of the suggestive name 'componentPOA', this POA can actually be any kind of POA,
* so that also client application can use the offshoot mechanism.
* <p>
* This method is synchronized inside to avoid race conditions between several offshoot POA creation/retrievals,
* where otherwise the POA would fail to be created even though first it was not found for reuse.
*
* @param componentPOA the POA of the component that owns the offshoot object;
* will become the parent of the offshoot POA.
* @return POA non-persistent POA for offshoot objects for the current component.
*
* @throws AcsJContainerServicesEx
*/
public POA getPOAForOffshoots(POA componentPOA) throws AcsJContainerEx, AcsJUnexpectedExceptionEx {
final String offshootPoaName = "offshootPoa";
POA offshootPoa = null;
synchronized (componentPOA) {
try {
// can we reuse it?
offshootPoa = componentPOA.find_POA(offshootPoaName, false);
} catch (AdapterNonExistent e) {
m_logger.finest("will have to create offshoot POA");
if (m_offshootPolicies == null) {
m_offshootPolicies = new Policy[4];
m_offshootPolicies[0] = componentPOA.create_id_assignment_policy(IdAssignmentPolicyValue.SYSTEM_ID);
m_offshootPolicies[1] = componentPOA.create_lifespan_policy(LifespanPolicyValue.TRANSIENT);
m_offshootPolicies[2] = componentPOA.create_request_processing_policy(RequestProcessingPolicyValue.USE_ACTIVE_OBJECT_MAP_ONLY);
m_offshootPolicies[3] = componentPOA.create_servant_retention_policy(ServantRetentionPolicyValue.RETAIN);
}
try {
offshootPoa = componentPOA.create_POA(offshootPoaName, sharedPoaManager, m_offshootPolicies);
m_logger.finest("successfully created offshoot POA");
} catch (InvalidPolicy ex) {
AcsJContainerEx ex2 = new AcsJContainerEx(ex);
ex2.setContextInfo("Attempted to create offshoot POA with invalid policies.");
throw ex2;
} catch (AdapterAlreadyExists ex) {
// we sync on componentPOA, so this should never happen
throw new AcsJUnexpectedExceptionEx(ex);
}
}
}
return offshootPoa;
}
use of alma.ACSErrTypeCommon.wrappers.AcsJUnexpectedExceptionEx in project ACS by ACS-Community.
the class AnyAide method complexObjectToCorbaAny.
/**
* Converts a complex CORBA-based object to a CORBA any.
*
* @param obj
* A complex CORBA-based object such as a user-defined IDL struct.
* @return A CORBA any containing obj.
* @throws AcsJException
* if any problem occurs with the conversion.
*/
public Any complexObjectToCorbaAny(IDLEntity obj) throws AcsJException {
if (obj == null) {
Throwable cause = new Throwable("Method arg 'obj' was null");
throw new AcsJBadParameterEx(cause);
}
Any retVal = m_containerServices.getAdvancedContainerServices().getAny();
// ------
Class structHelperClass = null;
// actually looks like a CORBA type.
try {
// This is the CORBA helper class which is capable of inserting/extracting data from CORBA Anys.
structHelperClass = Class.forName(obj.getClass().getName() + "Helper");
} catch (Exception e) {
// If what's above fails...then the developer has specified a native Java
// class which has nothing to do with CORBA.
String msg = "The non-CORBA class '" + obj.getClass().getName() + "' cannot be converted to a CORBA Any.";
Throwable cause = new Throwable(msg);
m_logger.warning(msg);
throw new alma.ACSErrTypeCommon.wrappers.AcsJTypeNotFoundEx(cause);
}
try {
// get at the static insert method defined for all IDL structures and sequences.
// TODO: Cache it in a struct - method map, perhaps using weak references.
Method insert = structHelperClass.getMethod("insert", new Class[] { Any.class, obj.getClass() });
// arguments to insert method are just the newly created Any and the
// IDL struct instance passed to this method.
Object[] args = { retVal, obj };
insert.invoke(null, args);
return retVal;
} catch (NoSuchMethodException e) {
// we got a Helper class, but it seems to be not the CORBA-generated kind
Throwable cause = new Throwable("Class '" + structHelperClass.getName() + "' associated with the given object of type '" + obj.getClass().getName() + "' is incompatiable with CORBA: " + e.getMessage());
throw new AcsJBadParameterEx(cause);
} catch (java.lang.reflect.InvocationTargetException e) {
Throwable realEx = e.getCause();
String reason = "Failed to insert the given CORBA object into a CORBA Any: the helper class insert method threw an exception.";
m_logger.log(Level.FINE, reason, realEx);
Throwable cause = new Throwable(reason + realEx.getMessage());
// todo: NC-specific exception type
throw new alma.ACSErrTypeJavaNative.wrappers.AcsJJavaLangEx(cause);
} catch (Throwable thr) {
String reason = "Failed to insert the given CORBA object into a CORBA Any.";
m_logger.log(Level.FINE, reason, thr);
Throwable cause = new Throwable(reason + thr.getMessage());
throw new AcsJUnexpectedExceptionEx(cause);
}
}
use of alma.ACSErrTypeCommon.wrappers.AcsJUnexpectedExceptionEx in project ACS by ACS-Community.
the class Helper method getNotificationChannel.
/**
* This method gets a reference to the event channel. If it is not already
* registered with the naming service, it is created.
*
* @return Reference to the event channel specified by channelName. Never null.
* @param channelKind
* Kind of the channel as registered with the CORBA naming service ("channels").
* @param notifyFactoryName
* Name of the notification service as registered with the CORBA
* naming service.
* @throws AcsJException
* Standard ACS Java exception.
*/
protected EventChannel getNotificationChannel(String notifyFactoryName) throws AcsJException {
String channelKind = NC_KIND.value;
// return value
EventChannel retValue = null;
NameComponent[] t_NameSequence = { new NameComponent(combineChannelAndDomainName(channelName, domainName), channelKind) };
// (retryNumberAttempts * retrySleepSec) = the time before we give up to get a reference or create the channel if
// a channel of the given name supposedly gets created already (due to race conditions with other clients).
int retryNumberAttempts = 20;
int retrySleepSec = 2;
do {
try {
// @TODO move the check for existing channel from naming service to the NC factory,
// now that we use the TAO extension with named NCs.
// The only advantage of still using the naming service is that the naming service is a real system-wide singleton
// and can return also channels that were by mistake created from a different notify service factory than the one configured in the CDB.
initializeNotifyFactory(notifyFactoryName);
retValue = EventChannelHelper.narrow(getNamingService().resolve(t_NameSequence));
} catch (org.omg.CosNaming.NamingContextPackage.NotFound e) {
// No other consumers or suppliers have registered the channel yet...
// This can mean that the channel has never been created, or that it is currently being created but has not yet been registered.
} catch (org.omg.CosNaming.NamingContextPackage.CannotProceed e) {
// Think there is virtually no chance of this every happening but...
throw new AcsJUnexpectedExceptionEx(e);
} catch (org.omg.CosNaming.NamingContextPackage.InvalidName e) {
// Think there is virtually no chance of this every happening but...
throw new AcsJUnexpectedExceptionEx(e);
}
if (retValue == null) {
// but only because we use the TAO extensions that support named NCs.
try {
retValue = createNotificationChannel(channelKind, notifyFactoryName);
} catch (NameAlreadyUsed ex) {
m_logger.log(Level.INFO, "NC '" + channelName + "' seems to be getting created. Will wait and try again in " + retrySleepSec + " seconds.", ex);
try {
Thread.sleep(retrySleepSec * 1000);
} catch (InterruptedException ex1) {
// too bad
}
}
} else // The channel could be resolved from the Naming Service
{
// Get the channel timestamp located into the Naming Service or set it to the current time
initChannelTimestamp();
// System.out.println("*** Got NC " + channelName + " from the naming service");
}
} while (retValue == null && --retryNumberAttempts >= 0);
if (retValue == null) {
AcsJGenericErrorEx ex = new AcsJGenericErrorEx();
ex.setErrorDesc("Giving up to get reference to channel " + channelName);
throw ex;
}
return retValue;
}
use of alma.ACSErrTypeCommon.wrappers.AcsJUnexpectedExceptionEx in project ACS by ACS-Community.
the class ManagerProxyImpl method release_component_async.
public void release_component_async(int id, String component_url, CBlong callback, CBDescIn desc) throws NoPermissionEx {
pendingRequests.incrementAndGet();
try {
// simply release Component
URI uri = null;
if (component_url != null)
uri = CURLHelper.createURI(component_url);
final CBlong fcallback = callback;
final CBDescOut descOut = new CBDescOut(0, desc.id_tag);
LongCompletionCallback lcc = null;
if (callback != null) {
lcc = new LongCompletionCallback() {
public void failed(int result, Throwable exception) {
if (exception instanceof AcsJException) {
AcsJException aex = (AcsJException) exception;
fcallback.done(result, aex.toAcsJCompletion().toCorbaCompletion(), descOut);
} else {
AcsJUnexpectedExceptionEx uex = new AcsJUnexpectedExceptionEx(exception);
fcallback.done(result, uex.toAcsJCompletion().toCorbaCompletion(), descOut);
}
}
public void done(int result) {
fcallback.done(result, new ACSErrOKAcsJCompletion().toCorbaCompletion(), descOut);
}
};
}
manager.releaseComponentAsync(id, uri, lcc);
} catch (AcsJNoPermissionEx nop) {
reportException(nop);
// rethrow CORBA specific
throw nop.toNoPermissionEx();
} catch (URISyntaxException usi) {
BadParametersException hbpe = new BadParametersException(usi.getMessage(), usi);
reportException(hbpe);
// rethrow CORBA specific
throw new BAD_PARAM(usi.getMessage());
} catch (BadParametersException bpe) {
BadParametersException hbpe = new BadParametersException(bpe.getMessage(), bpe);
reportException(hbpe);
// rethrow CORBA specific
throw new BAD_PARAM(bpe.getMessage());
} catch (NoResourcesException nre) {
NoResourcesException hnre = new NoResourcesException(nre.getMessage(), nre);
reportException(hnre);
// rethrow CORBA specific
throw new NO_RESOURCES(nre.getMessage());
} catch (Throwable ex) {
CoreException hce = new CoreException(ex.getMessage(), ex);
reportException(hce);
// rethrow CORBA specific
throw new UNKNOWN(ex.getMessage());
} finally {
pendingRequests.decrementAndGet();
}
}
Aggregations