INTSAMPLES-64 - Code Review Changes

* Better documentation in README.md
* Better error handling
* Using a better data-format
This commit is contained in:
Gunnar Hillert
2012-02-15 12:17:52 -05:00
parent edd3f90299
commit 3e7d121dd4
4 changed files with 34 additions and 14 deletions

View File

@@ -67,6 +67,7 @@ public class DynamicPeriodicTrigger implements Trigger {
* provided upon instantiation, the default is milliseconds.
*/
public void setInitialDelay(long initialDelay) {
Assert.isTrue(initialDelay >= 0, "initialDelay must not be negative");
this.initialDelay = this.timeUnit.toMillis(initialDelay);
}
@@ -97,6 +98,7 @@ public class DynamicPeriodicTrigger implements Trigger {
}
public void setPeriod(long period) {
Assert.isTrue(period >= 0, "period must not be negative");
this.period = period;
}
@@ -105,6 +107,7 @@ public class DynamicPeriodicTrigger implements Trigger {
}
public void setTimeUnit(TimeUnit timeUnit) {
Assert.notNull(timeUnit, "timeUnit must not be null");
this.timeUnit = timeUnit;
}

View File

@@ -66,16 +66,29 @@ public final class Main {
+ "\n=========================================================" );
System.out.print("Please enter a non-negative numeric value and press <enter>: ");
while (!scanner.hasNext("q")) {
while (true) {
int triggerPeriod = scanner.nextInt();
final String input = scanner.nextLine();
System.out.println(String.format("Setting trigger period to '%s' ms", triggerPeriod));
if("q".equals(input.trim())) {
break;
}
trigger.setPeriod(triggerPeriod);
try {
int triggerPeriod = Integer.valueOf(input);
System.out.println(String.format("Setting trigger period to '%s' ms", triggerPeriod));
trigger.setPeriod(triggerPeriod);
} catch (Exception e) {
LOGGER.error("An exception was caught: " + e);
}
System.out.print("Please enter a non-negative numeric value and press <enter>: ");
}
LOGGER.info("Exiting application...bye.");

View File

@@ -7,7 +7,7 @@
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:task="http://www.springframework.org/schema/task">
<int:inbound-channel-adapter expression="T(java.lang.System).currentTimeMillis()" channel="logger">
<int:inbound-channel-adapter expression="new java.text.SimpleDateFormat('yyyy-MM-dd HH:mm:ss.SSS').format(new java.util.Date())" channel="logger">
<int:poller max-messages-per-poll="1" trigger="dynamicTrigger" />
</int:inbound-channel-adapter>