@Stateless
@Name("paymentHandler")
public class PaymentHandlerBean implements PaymentHandler
{
@Asynchronous
public void processPayment(Payment payment) {
//do some work!
}
}
@Stateless
@Name("paymentHandler")
public class PaymentHandlerBean implements PaymentHandler
{
@Asynchronous
public void processPayment(Payment payment) {
//do some work!
}
}
Copy to ClipboardCopied!Toggle word wrapToggle overflow
非同期性の使用は Bean クラスには透過的です。また、クライアントにも透過的です。
@Stateful
@Name("paymentAction")
public class CreatePaymentAction
{
@In(create=true) PaymentHandler paymentHandler;
@In Bill bill;
public String pay() {
paymentHandler.processPayment( new Payment(bill) );
return "success";
}
}
@Stateful
@Name("paymentAction")
public class CreatePaymentAction
{
@In(create=true) PaymentHandler paymentHandler;
@In Bill bill;
public String pay() {
paymentHandler.processPayment( new Payment(bill) );
return "success";
}
}
Copy to ClipboardCopied!Toggle word wrapToggle overflow
@Local
public interface PaymentHandler {
@Asynchronous
public void processScheduledPayment(Payment payment,
@Expiration Date date);
@Asynchronous
public void processRecurringPayment(Payment payment,
@Expiration Date date,
@IntervalDuration Long interval);
}
@Local
public interface PaymentHandler {
@Asynchronous
public void processScheduledPayment(Payment payment,
@Expiration Date date);
@Asynchronous
public void processRecurringPayment(Payment payment,
@Expiration Date date,
@IntervalDuration Long interval);
}
Copy to ClipboardCopied!Toggle word wrapToggle overflow
@Stateful
@Name("paymentAction")
public class CreatePaymentAction
{
@In(create=true) PaymentHandler paymentHandler;
@In Bill bill;
public String schedulePayment() {
paymentHandler.processScheduledPayment(new Payment(bill),
bill.getDueDate() );
return "success";
}
public String scheduleRecurringPayment() {
paymentHandler.processRecurringPayment(new Payment(bill),
bill.getDueDate(), ONE_MONTH );
return "success";
}
}
@Stateful
@Name("paymentAction")
public class CreatePaymentAction
{
@In(create=true) PaymentHandler paymentHandler;
@In Bill bill;
public String schedulePayment() {
paymentHandler.processScheduledPayment(new Payment(bill),
bill.getDueDate() );
return "success";
}
public String scheduleRecurringPayment() {
paymentHandler.processRecurringPayment(new Payment(bill),
bill.getDueDate(), ONE_MONTH );
return "success";
}
}
Copy to ClipboardCopied!Toggle word wrapToggle overflow
@Local
public interface PaymentHandler
{
@Asynchronous
public Timer processScheduledPayment(Payment payment,
@Expiration Date date);
}
@Local
public interface PaymentHandler
{
@Asynchronous
public Timer processScheduledPayment(Payment payment,
@Expiration Date date);
}
Copy to ClipboardCopied!Toggle word wrapToggle overflow
@Stateless
@Name("paymentHandler")
public class PaymentHandlerBean implements PaymentHandler {
@In Timer timer;
public Timer processScheduledPayment(Payment payment,
@Expiration Date date) {
//do some work!
return timer; //note that return value is completely ignored
}
}
@Stateless
@Name("paymentHandler")
public class PaymentHandlerBean implements PaymentHandler {
@In Timer timer;
public Timer processScheduledPayment(Payment payment,
@Expiration Date date) {
//do some work!
return timer; //note that return value is completely ignored
}
}
Copy to ClipboardCopied!Toggle word wrapToggle overflow
@Stateful
@Name("paymentAction")
public class CreatePaymentAction
{
@In(create=true) PaymentHandler paymentHandler;
@In Bill bill;
public String schedulePayment() {
Timer timer =
paymentHandler.processScheduledPayment(new Payment(bill),
bill.getDueDate());
return "success";
}
}
@Stateful
@Name("paymentAction")
public class CreatePaymentAction
{
@In(create=true) PaymentHandler paymentHandler;
@In Bill bill;
public String schedulePayment() {
Timer timer =
paymentHandler.processScheduledPayment(new Payment(bill),
bill.getDueDate());
return "success";
}
}
Copy to ClipboardCopied!Toggle word wrapToggle overflow
@In QuartzTriggerHandle timer;
// Defines the method in the "processor" component
@Asynchronous
public QuartzTriggerHandle schedulePayment(@Expiration Date when,
@IntervalDuration Long interval,
@FinalExpiration Date endDate,
Payment payment) {
// do the repeating or long running task until endDate
}
... ...
// Schedule the task in the business logic processing code
// Starts now, repeats every hour, and ends on May 10th, 2010
Calendar cal = Calendar.getInstance ();
cal.set (2010, Calendar.MAY, 10);
processor.schedulePayment(new Date(), 60*60*1000, cal.getTime(), payment);
@In QuartzTriggerHandle timer;
// Defines the method in the "processor" component
@Asynchronous
public QuartzTriggerHandle schedulePayment(@Expiration Date when,
@IntervalDuration Long interval,
@FinalExpiration Date endDate,
Payment payment) {
// do the repeating or long running task until endDate
}
... ...
// Schedule the task in the business logic processing code
// Starts now, repeats every hour, and ends on May 10th, 2010
Calendar cal = Calendar.getInstance ();
cal.set (2010, Calendar.MAY, 10);
processor.schedulePayment(new Date(), 60*60*1000, cal.getTime(), payment);
Copy to ClipboardCopied!Toggle word wrapToggle overflow
QuartzTriggerHandle handle=
processor.schedulePayment(payment.getPaymentDate(),
payment.getPaymentCron(),
payment);
payment.setQuartzTriggerHandle( handle );
// Save payment to DB
// later ...
// Retrieve payment from DB
// Cancel the remaining scheduled tasks
payment.getQuartzTriggerHandle().cancel();
QuartzTriggerHandle handle=
processor.schedulePayment(payment.getPaymentDate(),
payment.getPaymentCron(),
payment);
payment.setQuartzTriggerHandle( handle );
// Save payment to DB
// later ...
// Retrieve payment from DB
// Cancel the remaining scheduled tasks
payment.getQuartzTriggerHandle().cancel();
Copy to ClipboardCopied!Toggle word wrapToggle overflow
// Define the method
@Asynchronous
public QuartzTriggerHandle schedulePayment(@Expiration Date when,
@IntervalCron String cron,
Payment payment) {
// do the repeating or long running task
}
... ...
// Schedule the task in the business logic processing code
QuartzTriggerHandle handle =
processor.schedulePayment(new Date(), "0 10,44 14 ? 3 WED", payment);
// Define the method
@Asynchronous
public QuartzTriggerHandle schedulePayment(@Expiration Date when,
@IntervalCron String cron,
Payment payment) {
// do the repeating or long running task
}
... ...
// Schedule the task in the business logic processing code
QuartzTriggerHandle handle =
processor.schedulePayment(new Date(), "0 10,44 14 ? 3 WED", payment);
Copy to ClipboardCopied!Toggle word wrapToggle overflow
// Define the method
@Asynchronous
public QuartzTriggerHandle schedulePayment(@Expiration Date when,
@IntervalBusinessDay NthBusinessDay nth,
Payment payment) {
// do the repeating or long running task
}
... ...
// Schedule the task in the business logic processing code
QuartzTriggerHandle handle =
processor.schedulePayment(new Date(),
new NthBusinessDay(2, "14:00", WEEKLY),
payment);
// Define the method
@Asynchronous
public QuartzTriggerHandle schedulePayment(@Expiration Date when,
@IntervalBusinessDay NthBusinessDay nth,
Payment payment) {
// do the repeating or long running task
}
... ...
// Schedule the task in the business logic processing code
QuartzTriggerHandle handle =
processor.schedulePayment(new Date(),
new NthBusinessDay(2, "14:00", WEEKLY),
payment);
Copy to ClipboardCopied!Toggle word wrapToggle overflow