package com.Bit4Tat;
import java.util.Date;
import java.util.concurrent.PriorityBlockingQueue;
{
private PriorityBlockingQueue<Transaction> transactions;
private boolean stopped;
private int pollInterval;
private final static int BUY = 0;
private final static int SELL = 1;
{
pollInterval = 6000;
stopped = false;
transactions = new PriorityBlockingQueue<Transaction>();
}
@Override
{
while (stopped == false) {
if (!transactions.isEmpty()) {
Transaction t = transactions.peek();
System.out.print("[");
for (Transaction t2: transactions) {
System.out.print(t2.amount + ", ");
}
System.out.println("]");
System.out.println(t.triggerTime + " - ");
System.out.println(System.currentTimeMillis() + " = ");
System.out.println(t.triggerTime - System.currentTimeMillis());
System.out.println(" -- " + t.expireTime);
if (!t.isExpired()) {
long curTime = System.currentTimeMillis();
if (t.triggerTime - curTime <= 0) {
t = transactions.poll();
switch (t.action) {
case BUY:
case SELL:
}
t.w = pollBalance(t.w);
}
else {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
else {
System.out.println("\n [expired: " + t.amount + "] \n");
transactions.poll();
}
}
else {
stopped = true;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
@Override
{
return cred;
}
@Override
double amount, Object expires) {
transactions.add(new Transaction(w, trigger, action, amount, expires));
}
@Override
{
System.out.println("Default Simple Scheduler in use.");
}
@Override
{
}
}
public Transaction (Wallet w, Object trigger,
int action,
double amount, Object expires) {
this.w = w;
this.action = action;
this.amount = amount;
expireTime = 0;
triggerTime = 0;
if (trigger instanceof Date) {
triggerTime = ((Date)trigger).getTime();
}
else {
triggerTime = System.currentTimeMillis() + pollInterval;
}
if (expires instanceof Date) {
expireTime = ((Date)expires).getTime();
}
}
@Override
if (((Long)triggerTime).compareTo(t.triggerTime) < 1)
return -1;
else
return 1;
}
if (expireTime == 0)
return false;
long curTime = System.currentTimeMillis();
if (expireTime - curTime <= 0)
return true;
else
return false;
}
Wallet w;
int action;
double amount;
long expireTime;
long triggerTime;
}
}