use of alma.acs.util.StopWatch in project ACS by ACS-Community.
the class CorbaNotifyConsumerImpl method receiveEvents.
@Override
public int receiveEvents(NcEventSpec[] ncEventSpecs, int processingDelayMillis, int numberOfEvents) throws CouldntPerformActionEx {
if (receiveMethodCalled.getAndSet(true)) {
AcsJCouldntPerformActionEx ex = new AcsJCouldntPerformActionEx("Method receiveEvents can be called only once during the component lifecycle.");
throw ex.toCouldntPerformActionEx();
}
if (cancel) {
AcsJCouldntPerformActionEx ex = new AcsJCouldntPerformActionEx("Method receiveEvents cannot be called after interrupt / ncDisconnect.");
throw ex.toCouldntPerformActionEx();
}
m_logger.info("Will receive events on " + ncEventSpecs.length + " NC(s), with processingDelayMillis=" + processingDelayMillis + ", numberOfEvents=" + (numberOfEvents > 0 ? numberOfEvents : "infinite"));
// sync object used to wait for numberOfEvents (if specified)
if (numberOfEvents > 0) {
sharedEventCountdown = new CountDownLatch(numberOfEvents);
}
StopWatch sw = new StopWatch();
try {
// iterate over NCs
for (NcEventSpec ncEventSpec : ncEventSpecs) {
AcsEventSubscriber<IDLEntity> sub = subsOrPubs.get(ncEventSpec.ncName);
if (sub == null) {
throw new AcsJCouldntPerformActionEx("No subscriber available for NC '" + ncEventSpec.ncName + "'.");
}
// iterate over event types
for (String eventName : ncEventSpec.eventNames) {
sub.addSubscription(createEventHandler(eventName, ncEventSpec.antennaName, processingDelayMillis));
m_logger.info("Added subscription for event=" + eventName + ", NC=" + ncEventSpec.ncName);
}
sub.startReceivingEvents();
}
} catch (AcsJCouldntPerformActionEx ex) {
ex.printStackTrace();
throw ex.toCouldntPerformActionEx();
} catch (Exception ex) {
ex.printStackTrace();
throw new AcsJCouldntPerformActionEx(ex).toCouldntPerformActionEx();
}
m_logger.info(ncEventSpecs.length + " subscriber(s) set up to receive events, which took " + sw.getLapTimeMillis() + " ms.");
if (numberOfEvents > 0) {
m_logger.info("Will wait for a total of " + numberOfEvents + " events to be received, with timeout after 10 minutes.");
try {
boolean cleanTermination = sharedEventCountdown.await(10, TimeUnit.MINUTES);
if (cleanTermination) {
m_logger.info("Received the expected " + numberOfEvents + " events in " + sw.getLapTimeMillis() + " ms.");
} else {
m_logger.warning("Unforeseen termination of event suppliers after 10 min (timeout).");
cancel = true;
}
} catch (InterruptedException ex) {
cancel = true;
}
} else {
m_logger.info("Will return from receiveEvents now but will keep receiving events.");
}
if (cancel) {
throw new AcsJCouldntPerformActionEx("Event receiving was interrupted or failed otherwise.").toCouldntPerformActionEx();
} else {
long receptionTimeNanos = (numberOfEvents > 0 && firstEventReceivedTimeNanos.longValue() > 0 ? (System.nanoTime() - firstEventReceivedTimeNanos.longValue()) : -1);
return (int) TimeUnit.NANOSECONDS.toMillis(receptionTimeNanos);
}
}
use of alma.acs.util.StopWatch in project ACS by ACS-Community.
the class DALImpl method loadRecords.
/**
* Returns a xml constructed of all records below given curl
*
* @param curl
* @param toString
* @return
* @throws AcsJCDBRecordDoesNotExistEx
* @throws AcsJCDBXMLErrorEx
*/
public XMLHandler loadRecords(String curl, boolean toString) throws AcsJCDBRecordDoesNotExistEx, AcsJCDBXMLErrorEx {
StopWatch sw = new StopWatch(m_logger);
try {
// create hierarchy of all nodes if it is not created yet
synchronized (this) {
if (rootNode == null) {
//no Error thrown
rootNode = DALNode.getRoot(m_root);
}
}
//no Error thrown
String strFileCurl = curl;
String strNodeCurl = "";
DALNode curlNode = null;
boolean isEmbeddedNode = false;
while (strFileCurl != null) {
curlNode = rootNode.findNode(strFileCurl);
if (curlNode == null) {
// Therefore we must move up toward the root node to find a valid parent xml node.
if (strFileCurl.lastIndexOf('/') > 0) {
strNodeCurl = strFileCurl.substring(strFileCurl.lastIndexOf('/') + 1) + "/" + strNodeCurl;
strFileCurl = strFileCurl.substring(0, strFileCurl.lastIndexOf('/'));
isEmbeddedNode = true;
} else {
strFileCurl = null;
}
} else {
// curlNode and strFileCurl point to the node that has the relevant XML file
break;
}
}
m_logger.log(AcsLogLevel.DEBUG, "loadRecords(curl=" + curl + "), strFileCurl=" + strFileCurl + ", strNodeCurl=" + strNodeCurl);
// because the "embedded" node data will not be found in other XML files.
if (strFileCurl == null || (isEmbeddedNode && !curlNode.hasXmlChild())) {
AcsJCDBRecordDoesNotExistEx recordDoesNotExist = new AcsJCDBRecordDoesNotExistEx();
recordDoesNotExist.setCurl(curl);
throw recordDoesNotExist;
}
if (curlNode.isSimple()) {
m_logger.log(AcsLogLevel.DEBUG, "loadRecords(curl=" + curl + "); curlNode '" + curlNode.name + "' is simple.");
if (curl.equals(strFileCurl)) {
return loadRecord(strFileCurl, toString);
} else {
XMLHandler xmlSolver = loadRecord(strFileCurl, false);
try {
return xmlSolver.getChild(strNodeCurl);
} catch (AcsJCDBRecordDoesNotExistEx e) {
e.setCurl(strFileCurl + e.getCurl());
throw e;
}
}
}
m_logger.log(AcsLogLevel.DEBUG, "loadRecords(curl=" + curl + "), curlNode is Complex");
XMLHandler xmlSolver;
try {
//xmlSolver.startElement(null,null,"curl",new org.xml.sax.helpers.AttributesImpl);
if (curl.equals(strFileCurl)) {
xmlSolver = new XMLHandler(toString, m_logger);
xmlSolver.setAutoCloseStartingElement(false);
parseNode(curlNode, xmlSolver, "");
//xmlSolver.closeElement();
return xmlSolver;
} else {
//here we must return the node inside the xmlSolver with curl= strNodeCurl
xmlSolver = new XMLHandler(false, m_logger);
xmlSolver.setMarkArrays(1);
xmlSolver.setAutoCloseStartingElement(false);
parseNode(curlNode, xmlSolver, "");
return xmlSolver.getChild(strNodeCurl);
}
} catch (AcsJCDBRecordDoesNotExistEx e) {
e.setCurl(strFileCurl + e.getCurl());
throw e;
} catch (SAXParseException e) {
AcsJCDBXMLErrorEx cdbxmlErr = new AcsJCDBXMLErrorEx();
cdbxmlErr.setErrorString("SAXParseException: " + e.getMessage());
cdbxmlErr.setCurl(curl);
cdbxmlErr.setFilename(e.getSystemId() + ", line=" + e.getLineNumber());
throw cdbxmlErr;
} catch (Throwable thr) {
AcsJCDBXMLErrorEx cdbxmlErr = new AcsJCDBXMLErrorEx(thr);
cdbxmlErr.setCurl(curl);
throw cdbxmlErr;
}
} finally {
long lt = sw.getLapTimeMillis();
m_logger.finest("Time spent in loadRecords(" + curl + "): " + lt);
}
}
use of alma.acs.util.StopWatch in project ACS by ACS-Community.
the class EntityRefFinder method findEntityReferences.
public EntityRefT[] findEntityReferences(Object rootEntityObject) throws EntityException {
ArrayList<EntityRefT> entityRefs = new ArrayList<EntityRefT>();
StopWatch stopw = new StopWatch(null);
recursiveFindEntityReferences(rootEntityObject, entityRefs);
if (m_debug) {
System.out.println("findEntityReferences took " + stopw.getLapTimeMillis() + " ms.");
}
return (entityRefs.toArray(new EntityRefT[0]));
}
use of alma.acs.util.StopWatch in project ACS by ACS-Community.
the class ManagerStdoutParser method parse.
public List<ComponentRequest> parse(File stdoutLogFile) throws IOException, ParseException {
if (stdoutLogFile == null) {
throw new IllegalArgumentException("No log file specified (null).");
} else if (!stdoutLogFile.exists() || !stdoutLogFile.canRead()) {
throw new IllegalArgumentException("Log file " + stdoutLogFile.getAbsolutePath() + " does not exist or cannot be read.");
}
StopWatch sw = new StopWatch(logger);
Map<ComponentRequestKey, List<ComponentRequest>> pendingRequests = new HashMap<ComponentRequestKey, List<ComponentRequest>>();
List<ComponentRequest> finishedRequests = new ArrayList<ComponentRequest>();
BufferedReader reader = new BufferedReader(new FileReader(stdoutLogFile));
String line = null;
int lineCount = 0;
while ((line = reader.readLine()) != null) {
lineCount++;
parseLine(line, pendingRequests, finishedRequests);
}
reader.close();
logger.info("Parsed file " + stdoutLogFile.getAbsolutePath() + " in " + sw.getLapTimeMillis() + " ms, found " + lineCount + " lines total, and " + finishedRequests.size() + " component activations.");
// Check for unfinished requests (may be pending, or may have failed which we don't parse out yet)
StringBuilder b = new StringBuilder();
for (ComponentRequestKey key : pendingRequests.keySet()) {
b.append(key.toString() + ": " + pendingRequests.get(key).size() + "\n");
}
logger.info("Unfinished or failed component requests: " + (b.length() > 0 ? "\n" + b.toString() : "none"));
return finishedRequests;
}
use of alma.acs.util.StopWatch in project ACS by ACS-Community.
the class Helper method createNotificationChannel.
/**
* Tries to create a notification channel (using quality of service and administrative properties
* specified by configQofS() and configAdminProps() respectively).
* If this succeeds, then registers this channel with the naming service.
* <p>
* Should only be invoked when the channel that this supplier or consumer is attempting to connect to
* does not exist.
* However even with prior check for the existence of this channel, a race condition with other suppliers or consumers
* can lead to multiple attempts to create the same channel, which will result in <code>NameAlreadyUsed</code> exception.
* <p>
* Design note: Currently the TAO notification extensions are used to synch channel creation with other clients
* by supplying the channel name to the factory.
* If we want to use only standard NC factories then we'd have to implement our own locking mechanisms in all
* ACS consumer and supplier classes, see http://jira.alma.cl/browse/COMP-2808
*
* @return Reference to the newly created channel.
* @param channelKind
* Kind of the channel as registered with the CORBA naming service.
* @param notifyFactoryName
* Name of the notification service as registered with the CORBA naming service.
* @throws AcsJException
* Standard ACS Java exception.
* @throws NameAlreadyUsed thrown if the channel of this name already exists.
*/
protected EventChannel createNotificationChannel(String channelKind, String notifyFactoryName) throws AcsJException, NameAlreadyUsed {
LOG_NC_ChannelCreated_ATTEMPT.log(m_logger, channelName, notifyFactoryName);
// return value
EventChannel retValue = null;
// to be assigned by factory
channelId = -1;
StopWatch stopwatch = new StopWatch();
try {
initializeNotifyFactory(notifyFactoryName);
// create the channel
// here we use the channel properties taken directly from our channel properties helper object.
// presumably these values come from the ACS configuration database.
IntHolder channelIdHolder = new IntHolder();
retValue = createNotifyChannel_internal(m_channelProperties.configQofS(channelName), m_channelProperties.configAdminProps(channelName), channelIdHolder);
// sanity check
if (retValue == null) {
// a null reference implies we cannot go any further
Throwable cause = new Throwable("Null reference obtained for the '" + channelName + "' channel!");
// TODO: more specific ex type
throw new alma.ACSErrTypeJavaNative.wrappers.AcsJJavaLangEx(cause);
}
channelId = channelIdHolder.value;
// register our new channel with the naming service
try {
NameComponent[] t_NameChannel = { new NameComponent(combineChannelAndDomainName(channelName, domainName), channelKind) };
getNamingService().rebind(t_NameChannel, retValue);
// Create an entry into the Naming Service to store the timestamp of the channel in order to allow
// subscribers to reconnect to the channel (ICT-4730)
int maxNumAttempts = 10;
int nAttempts = maxNumAttempts;
boolean timestampCreated = setChannelTimestamp(retValue);
while (false == timestampCreated && nAttempts > 0) {
try {
Thread.sleep(2000);
} catch (InterruptedException ex1) {
// too bad
}
nAttempts--;
timestampCreated = setChannelTimestamp(retValue);
}
if (false == timestampCreated) {
Throwable cause = new Throwable("Failed to register the timestamp of the channel '" + channelName + "' into the Naming Service after " + String.valueOf(maxNumAttempts) + " attempts");
// TODO: more specific ex type
throw new alma.ACSErrTypeJavaNative.wrappers.AcsJJavaLangEx(cause);
}
} catch (org.omg.CosNaming.NamingContextPackage.NotFound ex) {
// Corba spec: "If already bound, the previous binding must be of type nobject;
// otherwise, a NotFound exception with a why reason of not_object is raised."
String reason = "Failed to register the new channel '" + channelName + "' with the Naming Service: " + ex.why.toString();
AcsJCORBAProblemEx ex2 = new AcsJCORBAProblemEx(ex);
ex2.setInfo(reason);
throw ex2;
}
} catch (org.omg.CosNaming.NamingContextPackage.CannotProceed e) {
// Think there is virtually no chance of this every happening but...
Throwable cause = new Throwable(e.getMessage());
throw new alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx(cause);
} catch (org.omg.CosNaming.NamingContextPackage.InvalidName e) {
// Think there is virtually no chance of this every happening but...
Throwable cause = new Throwable(e.getMessage());
throw new alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx(cause);
} catch (org.omg.CosNotification.UnsupportedQoS e) {
Throwable cause = new Throwable("The quality of service properties specified for the '" + channelName + "' channel are unsupported: " + e.getMessage());
throw new alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx(cause);
}
LOG_NC_ChannelCreated_OK.log(m_logger, channelName, channelId, notifyFactoryName, stopwatch.getLapTimeMillis());
return retValue;
}
Aggregations