use of org.apache.camel.util.StopWatch in project camel by apache.
the class AsyncJmsInOutTempDestIT method testAsynchronous.
@Test
public void testAsynchronous() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(100);
mock.expectsNoDuplicates(body());
StopWatch watch = new StopWatch();
for (int i = 0; i < 100; i++) {
template.sendBody("seda:start", "" + i);
}
// just in case we run on slow boxes
assertMockEndpointsSatisfied(20, TimeUnit.SECONDS);
log.info("Took " + watch.stop() + " ms. to process 100 messages request/reply over JMS");
}
use of org.apache.camel.util.StopWatch in project camel by apache.
the class SyncJmsInOutIT method testSynchronous.
@Test
public void testSynchronous() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(100);
mock.expectsNoDuplicates(body());
StopWatch watch = new StopWatch();
for (int i = 0; i < 100; i++) {
template.sendBody("seda:start", "" + i);
}
// just in case we run on slow boxes
assertMockEndpointsSatisfied(20, TimeUnit.SECONDS);
log.info("Took " + watch.stop() + " ms. to process 100 messages request/reply over JMS");
}
use of org.apache.camel.util.StopWatch in project camel by apache.
the class FtpChangedExclusiveReadLockStrategy method acquireExclusiveReadLock.
public boolean acquireExclusiveReadLock(GenericFileOperations<FTPFile> operations, GenericFile<FTPFile> file, Exchange exchange) throws Exception {
boolean exclusive = false;
LOG.trace("Waiting for exclusive read lock to file: " + file);
long lastModified = Long.MIN_VALUE;
long length = Long.MIN_VALUE;
StopWatch watch = new StopWatch();
long startTime = new Date().getTime();
while (!exclusive) {
// timeout check
if (timeout > 0) {
long delta = watch.taken();
if (delta > timeout) {
CamelLogger.log(LOG, readLockLoggingLevel, "Cannot acquire read lock within " + timeout + " millis. Will skip the file: " + file);
// we could not get the lock within the timeout period, so return false
return false;
}
}
long newLastModified = 0;
long newLength = 0;
List<FTPFile> files;
if (fastExistsCheck) {
// use the absolute file path to only pickup the file we want to check, this avoids expensive
// list operations if we have a lot of files in the directory
String path = file.getAbsoluteFilePath();
if (path.equals("/") || path.equals("\\")) {
// special for root (= home) directory
LOG.trace("Using fast exists to update file information in home directory");
files = operations.listFiles();
} else {
LOG.trace("Using fast exists to update file information for {}", path);
files = operations.listFiles(path);
}
} else {
// fast option not enabled, so list the directory and filter the file name
String path = file.getParent();
if (path.equals("/") || path.equals("\\")) {
// special for root (= home) directory
LOG.trace("Using full directory listing in home directory to update file information. Consider enabling fastExistsCheck option.");
files = operations.listFiles();
} else {
LOG.trace("Using full directory listing to update file information for {}. Consider enabling fastExistsCheck option.", path);
files = operations.listFiles(path);
}
}
LOG.trace("List files {} found {} files", file.getAbsoluteFilePath(), files.size());
for (FTPFile f : files) {
boolean match;
if (fastExistsCheck) {
// uses the absolute file path as well
match = f.getName().equals(file.getAbsoluteFilePath()) || f.getName().equals(file.getFileNameOnly());
} else {
match = f.getName().equals(file.getFileNameOnly());
}
if (match) {
newLength = f.getSize();
if (f.getTimestamp() != null) {
newLastModified = f.getTimestamp().getTimeInMillis();
}
}
}
LOG.trace("Previous last modified: " + lastModified + ", new last modified: " + newLastModified);
LOG.trace("Previous length: " + length + ", new length: " + newLength);
long newOlderThan = startTime + watch.taken() - minAge;
LOG.trace("New older than threshold: {}", newOlderThan);
if (newLength >= minLength && ((minAge == 0 && newLastModified == lastModified && newLength == length) || (minAge != 0 && newLastModified < newOlderThan))) {
LOG.trace("Read lock acquired.");
exclusive = true;
} else {
// set new base file change information
lastModified = newLastModified;
length = newLength;
boolean interrupted = sleep();
if (interrupted) {
// we were interrupted while sleeping, we are likely being shutdown so return false
return false;
}
}
}
return exclusive;
}
use of org.apache.camel.util.StopWatch in project camel by apache.
the class SftpChangedExclusiveReadLockStrategy method acquireExclusiveReadLock.
public boolean acquireExclusiveReadLock(GenericFileOperations<ChannelSftp.LsEntry> operations, GenericFile<ChannelSftp.LsEntry> file, Exchange exchange) throws Exception {
boolean exclusive = false;
LOG.trace("Waiting for exclusive read lock to file: " + file);
long lastModified = Long.MIN_VALUE;
long length = Long.MIN_VALUE;
StopWatch watch = new StopWatch();
long startTime = new Date().getTime();
while (!exclusive) {
// timeout check
if (timeout > 0) {
long delta = watch.taken();
if (delta > timeout) {
CamelLogger.log(LOG, readLockLoggingLevel, "Cannot acquire read lock within " + timeout + " millis. Will skip the file: " + file);
// we could not get the lock within the timeout period, so return false
return false;
}
}
long newLastModified = 0;
long newLength = 0;
List<ChannelSftp.LsEntry> files;
if (fastExistsCheck) {
// use the absolute file path to only pickup the file we want to check, this avoids expensive
// list operations if we have a lot of files in the directory
String path = file.getAbsoluteFilePath();
if (path.equals("/") || path.equals("\\")) {
// special for root (= home) directory
LOG.trace("Using fast exists to update file information in home directory");
files = operations.listFiles();
} else {
LOG.trace("Using fast exists to update file information for {}", path);
files = operations.listFiles(path);
}
} else {
String path = file.getParent();
if (path.equals("/") || path.equals("\\")) {
// special for root (= home) directory
LOG.trace("Using full directory listing in home directory to update file information. Consider enabling fastExistsCheck option.");
files = operations.listFiles();
} else {
LOG.trace("Using full directory listing to update file information for {}. Consider enabling fastExistsCheck option.", path);
files = operations.listFiles(path);
}
}
LOG.trace("List files {} found {} files", file.getAbsoluteFilePath(), files.size());
for (ChannelSftp.LsEntry f : files) {
boolean match;
if (fastExistsCheck) {
// uses the absolute file path as well
match = f.getFilename().equals(file.getAbsoluteFilePath()) || f.getFilename().equals(file.getFileNameOnly());
} else {
match = f.getFilename().equals(file.getFileNameOnly());
}
if (match) {
newLastModified = f.getAttrs().getMTime() * 1000L;
newLength = f.getAttrs().getSize();
}
}
LOG.trace("Previous last modified: " + lastModified + ", new last modified: " + newLastModified);
LOG.trace("Previous length: " + length + ", new length: " + newLength);
long newOlderThan = startTime + watch.taken() - minAge;
LOG.trace("New older than threshold: {}", newOlderThan);
if (newLength >= minLength && ((minAge == 0 && newLastModified == lastModified && newLength == length) || (minAge != 0 && newLastModified < newOlderThan))) {
LOG.trace("Read lock acquired.");
exclusive = true;
} else {
// set new base file change information
lastModified = newLastModified;
length = newLength;
boolean interrupted = sleep();
if (interrupted) {
// we were interrupted while sleeping, we are likely being shutdown so return false
return false;
}
}
}
return exclusive;
}
use of org.apache.camel.util.StopWatch in project camel by apache.
the class AggregateProcessor method restoreTimeoutMapFromAggregationRepository.
/**
* Restores the timeout map with timeout values from the aggregation repository.
* <p/>
* This is needed in case the aggregator has been stopped and started again (for example a server restart).
* Then the existing exchanges from the {@link AggregationRepository} must have their timeout conditions restored.
*/
protected void restoreTimeoutMapFromAggregationRepository() throws Exception {
// grab the timeout value for each partly aggregated exchange
Set<String> keys = aggregationRepository.getKeys();
if (keys == null || keys.isEmpty()) {
return;
}
StopWatch watch = new StopWatch();
LOG.trace("Starting restoring CompletionTimeout for {} existing exchanges from the aggregation repository...", keys.size());
for (String key : keys) {
Exchange exchange = aggregationRepository.get(camelContext, key);
// grab the timeout value
long timeout = exchange.hasProperties() ? exchange.getProperty(Exchange.AGGREGATED_TIMEOUT, 0, long.class) : 0;
if (timeout > 0) {
LOG.trace("Restoring CompletionTimeout for exchangeId: {} with timeout: {} millis.", exchange.getExchangeId(), timeout);
addExchangeToTimeoutMap(key, exchange, timeout);
}
}
// log duration of this task so end user can see how long it takes to pre-check this upon starting
LOG.info("Restored {} CompletionTimeout conditions in the AggregationTimeoutChecker in {}", timeoutMap.size(), TimeUtils.printDuration(watch.stop()));
}
Aggregations