Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew M. Finkbeiner2016-08-05 16:05:55 +0000
committerAndrew M. Finkbeiner2016-11-28 22:51:46 +0000
commitd9e91d652d6c0b3eaf8768ad59a29012d0198089 (patch)
tree68299d57c775d5869f0f20642bf3caa5cadbaf02
parente07f739f26418b3e4c80b0ea1d4d17688293f9c7 (diff)
downloadorg.eclipse.osee-d9e91d652d6c0b3eaf8768ad59a29012d0198089.tar.gz
org.eclipse.osee-d9e91d652d6c0b3eaf8768ad59a29012d0198089.tar.xz
org.eclipse.osee-d9e91d652d6c0b3eaf8768ad59a29012d0198089.zip
feature[ats_ATS302834]: Fix some scheduling issues
-rw-r--r--plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/OTETestEnvironmentClient.java10
-rw-r--r--plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/environment/interfaces/IHostTestEnvironment.java3
-rw-r--r--plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteEndpointReceiveRunnable.java1
-rw-r--r--plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteEndpointSender.java3
-rw-r--r--plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteUdpEndpointInlineSender.java17
-rw-r--r--plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteUdpEndpointSender.java24
-rw-r--r--plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/Message.java2
-rw-r--r--plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/PeriodicPublishMap.java10
-rw-r--r--plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/WaitOnCondition.java14
-rw-r--r--plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/send/OteEndpointSendEventMessage.java8
-rw-r--r--plugins/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/OteService.java11
-rw-r--r--plugins/org.eclipse.ote.scheduler/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/NodePool.java1
-rw-r--r--plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/OTEClockReal.java12
-rw-r--r--plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/OTETask.java16
-rw-r--r--plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/OTETaskHeavy.java8
-rw-r--r--plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/Scheduler.java10
-rw-r--r--plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/SchedulerImpl.java305
-rw-r--r--plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/SortedLinkedList.java386
-rw-r--r--plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/SortedLinkedListCopyOnWrite.java97
-rw-r--r--plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/SortedOnInsertList.java250
21 files changed, 220 insertions, 969 deletions
diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/OTETestEnvironmentClient.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/OTETestEnvironmentClient.java
index b42bfae3bae..8b69c6c84fd 100644
--- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/OTETestEnvironmentClient.java
+++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/OTETestEnvironmentClient.java
@@ -5,6 +5,7 @@ import java.io.FilenameFilter;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.URISyntaxException;
+import java.nio.ByteBuffer;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
@@ -379,6 +380,15 @@ public class OTETestEnvironmentClient {
e.printStackTrace();
}
}
+
+ public void send(ByteBuffer buffer) {
+ try {
+ OteEndpointSendEventMessage sendit = new OteEndpointSendEventMessage(service, destinationAddress);
+ sendit.asynchSend(buffer);
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/environment/interfaces/IHostTestEnvironment.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/environment/interfaces/IHostTestEnvironment.java
index 1212d3cff8d..26abef457fb 100644
--- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/environment/interfaces/IHostTestEnvironment.java
+++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/environment/interfaces/IHostTestEnvironment.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.osee.ote.core.environment.interfaces;
+import java.nio.ByteBuffer;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.UUID;
@@ -30,4 +31,6 @@ public interface IHostTestEnvironment extends Remote {
public String getHttpURL() throws RemoteException;
+ public void send(ByteBuffer buffer) throws RemoteException;
+
}
diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteEndpointReceiveRunnable.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteEndpointReceiveRunnable.java
index b7f79012b3a..f90ac5959c2 100644
--- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteEndpointReceiveRunnable.java
+++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteEndpointReceiveRunnable.java
@@ -121,6 +121,7 @@ public class OteEndpointReceiveRunnable implements Runnable {
for (EndpointDataProcessor processor : dataProcessors) {
if (processor.getTypeId() == typeId) {
try {
+ buffer.position(2);
processor.processBuffer(buffer);
} catch (Throwable th) {
th.printStackTrace();
diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteEndpointSender.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteEndpointSender.java
index 4a1a9e76e23..7349a0dd9d1 100644
--- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteEndpointSender.java
+++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteEndpointSender.java
@@ -1,12 +1,15 @@
package org.eclipse.osee.ote.endpoint;
import java.net.InetSocketAddress;
+import java.nio.ByteBuffer;
import org.eclipse.osee.ote.message.event.OteEventMessage;
public interface OteEndpointSender {
void send(OteEventMessage sendMessage);
+
+ void send(ByteBuffer buffer);
InetSocketAddress getAddress();
diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteUdpEndpointInlineSender.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteUdpEndpointInlineSender.java
index 3b6395a373a..2f191ae809b 100644
--- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteUdpEndpointInlineSender.java
+++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteUdpEndpointInlineSender.java
@@ -46,6 +46,21 @@ public class OteUdpEndpointInlineSender implements OteEndpointSender {
throw new OTEException(e);
}
}
+
+ @Override
+ public void send(ByteBuffer buffer) {
+ try {
+ DatagramChannel channel = DatagramChannel.open();
+ if (channel.socket().getSendBufferSize() < SEND_BUFFER_SIZE) {
+ channel.socket().setSendBufferSize(SEND_BUFFER_SIZE);
+ }
+ channel.socket().setReuseAddress(true);
+ channel.configureBlocking(true);
+ channel.send(buffer, address);
+ } catch (IOException e) {
+ throw new OTEException(e);
+ }
+ }
@Override
public void stop() {
@@ -67,4 +82,6 @@ public class OteUdpEndpointInlineSender implements OteEndpointSender {
//not needed
}
+
+
}
diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteUdpEndpointSender.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteUdpEndpointSender.java
index cbff4d91a6b..215a878ced1 100644
--- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteUdpEndpointSender.java
+++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteUdpEndpointSender.java
@@ -1,6 +1,7 @@
package org.eclipse.osee.ote.endpoint;
import java.net.InetSocketAddress;
+import java.nio.ByteBuffer;
import java.util.Date;
import java.util.concurrent.ArrayBlockingQueue;
@@ -81,6 +82,27 @@ public class OteUdpEndpointSender implements OteEndpointSender {
}
}
+
+ public void send(ByteBuffer buffer) {
+ if(debug){
+ System.out.printf("[%s] sending: [%s] to [%s] [%d]\n", new Date(), "ByteBuffer", address.toString(), buffer.remaining());
+ }
+ AddressBuffer obj = buffers.getObject();
+ obj.getBuffer().clear();
+ obj.getBuffer().put(buffer);
+ obj.getBuffer().flip();
+ obj.setAddress(address);
+ try {
+ if (!thread.isAlive()) {
+ // our thread has sat idle for too long and self terminated go ahead and start a new one
+ start();
+ }
+ toSend.put(obj);
+ } catch (InterruptedException e) {
+ throw new OTEException(e);
+ }
+
+ }
@Override
public boolean isClosed() {
@@ -92,4 +114,6 @@ public class OteUdpEndpointSender implements OteEndpointSender {
this.debug = debug;
}
+
+
}
diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/Message.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/Message.java
index 20d64c97b43..4d9156128bc 100644
--- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/Message.java
+++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/Message.java
@@ -858,6 +858,7 @@ public class Message implements Xmlizable, XmlizableStream {
setSchedule(true);
regularUnscheduleCalled = false;
if(messageManager != null){
+ messageManager.schedulePublish(this);
messageManager.notifySchedulingChangeListeners(this, true);
}
}
@@ -1029,6 +1030,7 @@ public class Message implements Xmlizable, XmlizableStream {
setSchedule(false);
regularUnscheduleCalled = true;
if(messageManager != null){
+ messageManager.unschedulePublish(this);
messageManager.notifySchedulingChangeListeners(this, false);
}
}
diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/PeriodicPublishMap.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/PeriodicPublishMap.java
index a0fc2fdf931..e282c104604 100644
--- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/PeriodicPublishMap.java
+++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/PeriodicPublishMap.java
@@ -6,8 +6,11 @@
package org.eclipse.osee.ote.message;
import org.eclipse.osee.framework.jdk.core.type.CompositeKeyHashMap;
+import org.eclipse.osee.ote.core.ServiceUtility;
import org.eclipse.osee.ote.core.environment.interfaces.ITimerControl;
import org.eclipse.osee.ote.message.interfaces.IMessageManager;
+import org.eclipse.osee.ote.message.timer.EnvTaskWrapper;
+import org.eclipse.ote.scheduler.Scheduler;
/**
* This is a helper class that stores the periodic publish tasks in a map based on the rate and phase of a message.
@@ -39,7 +42,12 @@ public class PeriodicPublishMap {
PeriodicPublishTask task = ratePhaseMap.get(rate, phase);
if(task == null){
task = new PeriodicPublishTask(messageManager, rate, phase);
- timerControl.addTask(task, null);
+ Scheduler scheduler = ServiceUtility.getService(Scheduler.class);
+ if(scheduler != null){
+ scheduler.scheduleAtFixedRate(new EnvTaskWrapper(task), task.getHzRate(), Integer.MAX_VALUE);
+ } else {
+ timerControl.addTask(task, null);
+ }
ratePhaseMap.put(rate, phase, task);
}
return task;
diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/WaitOnCondition.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/WaitOnCondition.java
index 723e0c4ee04..97f4a089450 100644
--- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/WaitOnCondition.java
+++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/WaitOnCondition.java
@@ -72,6 +72,7 @@ public class WaitOnCondition {
time = scheduler.getTime() - time;
} catch (InterruptedException e) {
} finally {
+ signalCheck.disable();
for(Message msg:messages){
msg.removeListener(signalCheck);
}
@@ -119,6 +120,7 @@ public class WaitOnCondition {
private ReentrantLock lock;
private Condition condition;
private ICondition check;
+ private volatile boolean ignore = false;
SignalNewData(ReentrantLock lock, Condition condition, ICondition check){
this.lock = lock;
@@ -126,13 +128,19 @@ public class WaitOnCondition {
this.check = check;
}
+ public void disable() {
+ this.ignore = true;
+ }
+
@Override
public void onDataAvailable(MessageData data, DataType type) throws MessageSystemException {
lock.lock();
try{
- scheduler.pauseSimulated(true);
- check.increment();
- condition.signal();
+ if(!ignore){
+ scheduler.pauseSimulated(true);
+ check.increment();
+ condition.signal();
+ }
// System.out.println(getClass().getSimpleName() + " SignalNewData - " + scheduler.getTime());
} finally {
lock.unlock();
diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/send/OteEndpointSendEventMessage.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/send/OteEndpointSendEventMessage.java
index cb12d805d2d..3b62bd3758d 100644
--- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/send/OteEndpointSendEventMessage.java
+++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/send/OteEndpointSendEventMessage.java
@@ -11,6 +11,7 @@
package org.eclipse.osee.ote.message.event.send;
import java.net.InetSocketAddress;
+import java.nio.ByteBuffer;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
@@ -45,6 +46,13 @@ public class OteEndpointSendEventMessage {
updateHeaderInfo(message);
endpoint.getOteEndpointThreadedSender(destination).send(message);
}
+
+ /**
+ * sends a message and returns immediately
+ */
+ public void asynchSend(ByteBuffer buffer) {
+ endpoint.getOteEndpointThreadedSender(destination).send(buffer);
+ }
/**
* Registers for a callback of the given message type as specified by the RESPONSE_TOPIC element in the sent message
diff --git a/plugins/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/OteService.java b/plugins/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/OteService.java
index 9d0e5d9dd0a..4ce493863a5 100644
--- a/plugins/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/OteService.java
+++ b/plugins/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/OteService.java
@@ -13,6 +13,7 @@ package org.eclipse.osee.ote.server.internal;
import java.io.File;
import java.io.FileOutputStream;
import java.io.Serializable;
+import java.nio.ByteBuffer;
import java.rmi.RemoteException;
import java.util.Collection;
import java.util.Date;
@@ -36,6 +37,7 @@ import org.eclipse.osee.ote.core.environment.TestEnvironmentConfig;
import org.eclipse.osee.ote.core.environment.interfaces.IHostTestEnvironment;
import org.eclipse.osee.ote.core.environment.interfaces.ITestEnvironment;
import org.eclipse.osee.ote.endpoint.OteUdpEndpoint;
+import org.eclipse.osee.ote.endpoint.OteUdpEndpointInlineSender;
import org.eclipse.osee.ote.io.OTEServerFolder;
import org.eclipse.osee.ote.message.MessageSystemTestEnvironment;
import org.eclipse.osee.ote.properties.OtePropertiesCore;
@@ -55,13 +57,17 @@ public class OteService implements IHostTestEnvironment {
// private final IRuntimeLibraryManager runtimeLibraryManager;
// private RegisteredServiceReference registeredServiceReference;
private OTESessionManager oteSessions;
+ private OteUdpEndpoint receiver;
+ private OteUdpEndpointInlineSender sender;
public OteService(EnvironmentCreationParameter environmentCreation, OTESessionManager oteSessions, PropertyParamter parameterObject, EnhancedProperties properties, OteUdpEndpoint receiver) {
// this.runtimeLibraryManager = runtimeLibraryManager;
this.environmentCreation = environmentCreation;
this.oteSessions = oteSessions;
+ this.receiver = receiver;
+ sender = receiver.getOteEndpointInlineSender(receiver.getLocalEndpoint());
Uuid uuid = UuidFactory.generate();
Long lsb = Long.valueOf(uuid.getLeastSignificantBits());
Long msb = Long.valueOf(uuid.getMostSignificantBits());
@@ -210,5 +216,10 @@ public class OteService implements IHostTestEnvironment {
public String getHttpURL() throws RemoteException {
return (String)enhancedProperties.getProperty("appServerURI");
}
+
+ @Override
+ public void send(ByteBuffer buffer) {
+ sender.send(buffer);
+ }
}
diff --git a/plugins/org.eclipse.ote.scheduler/META-INF/MANIFEST.MF b/plugins/org.eclipse.ote.scheduler/META-INF/MANIFEST.MF
index 848a53f2214..7c0193fcb6f 100644
--- a/plugins/org.eclipse.ote.scheduler/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.ote.scheduler/META-INF/MANIFEST.MF
@@ -4,3 +4,4 @@ Bundle-Name: Scheduler
Bundle-SymbolicName: org.eclipse.ote.scheduler
Bundle-Version: 0.23.1.qualifier
Export-Package: org.eclipse.ote.scheduler
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
diff --git a/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/NodePool.java b/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/NodePool.java
index a139cec6cd8..c6d8ecf3c01 100644
--- a/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/NodePool.java
+++ b/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/NodePool.java
@@ -35,6 +35,7 @@ public class NodePool<T extends Comparable<T>> {
return newNode;
}
+ @SuppressWarnings({ "rawtypes", "unchecked" })
public void pushNode(Node node) {
poolLock.lock();
try{
diff --git a/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/OTEClockReal.java b/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/OTEClockReal.java
index ffaafb72a4e..08fb724a3c9 100644
--- a/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/OTEClockReal.java
+++ b/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/OTEClockReal.java
@@ -4,7 +4,6 @@ public class OTEClockReal extends OTEClock {
private long lastStepTime = System.nanoTime();
private static final long step = 1000000;
- private int averageCount;
private Runnable delay;
public OTEClockReal(Runnable delay){
@@ -21,20 +20,9 @@ public class OTEClockReal extends OTEClock {
public void step(){
super.step();
- int count = 0;
while(System.nanoTime() - lastStepTime < step){
- //busy loop
- count++;
delay.run();
-// Thread.yield();
-// try {
-// Thread.sleep(0, 1);
-// } catch (InterruptedException e) {
-// // TODO Auto-generated catch block
-// e.printStackTrace();
-// }
}
-// System.out.println(count);
lastStepTime = System.nanoTime();
}
diff --git a/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/OTETask.java b/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/OTETask.java
index ea7ec2dd71b..b5bfe81c7f3 100644
--- a/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/OTETask.java
+++ b/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/OTETask.java
@@ -11,18 +11,21 @@ public class OTETask implements Callable<OTETaskResult>, Comparable<OTETask>{
private volatile boolean complete = false;
private volatile boolean canceled = false;
private boolean isMainThread = false;
+ private int weight = 0;
- public OTETask(Runnable runnable, int period){
+ public OTETask(Runnable runnable, int period, int weight){
isScheduled = true;
this.r = runnable;
this.period = period;
+ this.weight = weight;
}
- public OTETask(Runnable runnable, long time) {
+ public OTETask(Runnable runnable, long time, int weight) {
isScheduled = false;
this.time = time;
this.r = runnable;
this.period = 0;
+ this.weight = weight;
}
public long getTime() {
@@ -80,7 +83,14 @@ public class OTETask implements Callable<OTETaskResult>, Comparable<OTETask>{
} else if (periodDelta < 0){
return -1;
} else {
- return hashCode() - o.hashCode();
+ int weightDelta = weight - o.weight;
+ if(weightDelta > 0){
+ return 1;
+ } else if (weightDelta < 0){
+ return -1;
+ } else {
+ return hashCode() - o.hashCode();
+ }
}
}
}
diff --git a/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/OTETaskHeavy.java b/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/OTETaskHeavy.java
index 299792d71e2..abd0fe8df50 100644
--- a/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/OTETaskHeavy.java
+++ b/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/OTETaskHeavy.java
@@ -7,8 +7,8 @@ public class OTETaskHeavy extends OTETask {
private Stopwatch[] stopwatches;
private int count = 1;
- public OTETaskHeavy(Runnable runnable, int period){
- super(runnable, period);
+ public OTETaskHeavy(Runnable runnable, int period, int weight){
+ super(runnable, period, weight);
result = new OTETaskResult();
if(period == 6 ){
stopwatches = new Stopwatch[5];
@@ -19,8 +19,8 @@ public class OTETaskHeavy extends OTETask {
stopwatch = new Stopwatch(runnable.getClass().getSimpleName());
}
- public OTETaskHeavy(Runnable runnable, long time) {
- super(runnable, time);
+ public OTETaskHeavy(Runnable runnable, long time, int weight) {
+ super(runnable, time, weight);
result = new OTETaskResult();
stopwatch = new Stopwatch(runnable.toString());
}
diff --git a/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/Scheduler.java b/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/Scheduler.java
index b8492e9ac68..3d25d809d5e 100644
--- a/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/Scheduler.java
+++ b/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/Scheduler.java
@@ -9,6 +9,15 @@ public interface Scheduler {
public long getTime();
+
+ /**
+ *
+ * @param task
+ * @param hzRate
+ * @param weight a value to determine sorting within a frame
+ * @return
+ */
+ public OTETaskRegistration scheduleAtFixedRate(Runnable task, double hzRate, int weight);
public OTETaskRegistration scheduleAtFixedRate(Runnable runnable, double d);
/**
*
@@ -36,5 +45,6 @@ public interface Scheduler {
* @param pause
*/
public void setNoPause(boolean pause);
+
}
diff --git a/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/SchedulerImpl.java b/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/SchedulerImpl.java
index f5013423c6c..59a413b787b 100644
--- a/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/SchedulerImpl.java
+++ b/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/SchedulerImpl.java
@@ -13,8 +13,6 @@ import java.util.concurrent.locks.ReentrantLock;
public class SchedulerImpl implements Scheduler {
-// private ReentrantLock lock = new ReentrantLock();
-
public enum DelayStrategy{
busy, yeild, sleep
}
@@ -22,25 +20,18 @@ public class SchedulerImpl implements Scheduler {
private OTEClock clock;
private volatile boolean run = false;
-
-// private SortedOnInsertList<OTETask> tasks = new SortedOnInsertList<>(OTETask.class);
-// private SortedOnInsertList<OTETask> simulatedEnvNotifyTasks = new SortedOnInsertList<>(OTETask.class);
-
-// + private NavigableSet<OTETask> simulatedEnvNotifyTasks = new ConcurrentSkipListSet<OTETask>();
private SortedLinkedListCopyOnWrite<OTETask> tasks = new SortedLinkedListCopyOnWrite<OTETask>();
private SortedLinkedListCopyOnWrite<OTETask> simulatedEnvNotifyTasks = new SortedLinkedListCopyOnWrite<OTETask>();
private ExecutorService pool;
private boolean isTimeSimulated;
private List<Future<OTETaskResult>> submittedTasks;
-// private ConcurrentLinkedQueue<OTETask> newTasks;
private Thread mainTimer;
private Runnable busyDelay = () -> { };
private Runnable yieldDelay = () -> { Thread.yield(); };
private Runnable sleepDelay = () -> { try{ Thread.sleep(0, 1); } catch (Throwable th){} };
private volatile boolean noPause = false;
- private boolean doTasksHaveAnyMainThreadWaits = false;
private Thread mainThread;
private SchedulerImpl wallClockScheduler;
@@ -73,7 +64,6 @@ public class SchedulerImpl implements Scheduler {
}
}
submittedTasks = new ArrayList<Future<OTETaskResult>>();
-// newTasks = new ConcurrentLinkedQueue<OTETask>();
pool = Executors.newFixedThreadPool(10, new ThreadFactory() {
private int count = 0;
@Override
@@ -107,11 +97,10 @@ public class SchedulerImpl implements Scheduler {
void step(){
boolean paused = false;
if(isTimeSimulated) {
- if(pauseSimulated){
- paused = true;
- } else if (!noPause){
- try{
-// lock.lock();
+ synchronized (this) {
+ if(pauseSimulated){
+ paused = true;
+ } else {
long time = clock.currentTimeMillis();
MyInnerIterator<OTETask> simIt = simulatedEnvNotifyTasks.iterator();
while(simIt.hasNext()){
@@ -123,7 +112,6 @@ public class SchedulerImpl implements Scheduler {
System.out.println("boo");
}
simulatedEnvNotifyTasks.print();
-// simIt.remove();
task.call();
} catch (Exception ex){
ex.printStackTrace();
@@ -133,14 +121,11 @@ public class SchedulerImpl implements Scheduler {
}
}
simulatedEnvNotifyTasks.doneWithIterator(simIt);
- if(simulatedEnvNotifyTasks.isEmpty()){
- paused = true;
- } else {
-// simulatedEnvNotifyTasks.print();
+ if (!noPause) {
+ if(simulatedEnvNotifyTasks.isEmpty()){
+ paused = true;
+ }
}
- } finally {
-// simulatedEnvNotifyTasks.compact();
-// lock.unlock();
}
}
}
@@ -149,10 +134,6 @@ public class SchedulerImpl implements Scheduler {
} else {
executeTasks();
clock.step();
-
-// if(isTimeSimulated){
-// System.out.println(getTime());
-// }
}
}
@@ -180,40 +161,28 @@ public class SchedulerImpl implements Scheduler {
mainTimer.start();
}
}
-
+
private void executeTasks() {
long time = clock.currentTimeMillis();
- try{
-// lock.lock();
- if(!tasks.isEmpty()){
- MyInnerIterator<OTETask> it = tasks.iterator();
- while(it.hasNext()){
- OTETask task = it.next();
- if(task == null){
- System.out.println("what?");
- }
- if(task != null && task.getTime() <= time){
- submittedTasks.add(pool.submit(task));
- tasks.remove(task);
-// it.remove();
- if(task.isMainThread()){
- doTasksHaveAnyMainThreadWaits = false;
- }
- if(task.isScheduled()){
- task.setNextTime(time + task.period());
-// tasks.addToQueue(task);
- tasks.add(task);
- }
- } else {
- break;
- }
+ if(!tasks.isEmpty()){
+ MyInnerIterator<OTETask> it = tasks.iterator();
+ while(it.hasNext()){
+ OTETask task = it.next();
+ if(task == null){
+ System.out.println("what?");
+ }
+ if(task != null && task.getTime() <= time){
+ submittedTasks.add(pool.submit(task));
+ tasks.remove(task);
+ if(task.isScheduled()){
+ task.setNextTime(time + task.period());
+ tasks.add(task);
+ }
+ } else {
+ break;
}
- tasks.doneWithIterator(it);
-// tasks.compact();
-// tasks.flushAddQueue();
}
- } finally {
-// lock.unlock();
+ tasks.doneWithIterator(it);
}
if(isTimeSimulated){
for(int i = 0; i < submittedTasks.size(); i++){
@@ -229,28 +198,25 @@ public class SchedulerImpl implements Scheduler {
}
}
-
-
public long getTime() {
return clock.currentTimeMillis();
}
public OTETaskRegistration scheduleAtFixedRate(Runnable runnable, double d){
+ return scheduleAtFixedRate(runnable, d, 0);
+ }
+
+ public OTETaskRegistration scheduleAtFixedRate(Runnable runnable, double d, int weight){
if(d > 1000.0){
throw new IllegalArgumentException();
}
OTETaskRegistration reg;
double periodMS = 1000.0/d;
int period = (int)periodMS;
- OTETask task = new OTETaskHeavy(runnable, period);
+ OTETask task = new OTETaskHeavy(runnable, period, weight);
reg = new OTETaskRegistration(this, task);
- try{
-// lock.lock();
- if(!tasks.add(task)){
- System.out.println("no no");
- }
- } finally {
-// lock.unlock();
+ if(!tasks.add(task)){
+ throw new RuntimeException("Failed to add a scheduled task");
}
return reg;
}
@@ -265,39 +231,29 @@ public class SchedulerImpl implements Scheduler {
*/
public OTETaskRegistration scheduleWithDelay(Runnable runnable, long msInTheFuture, boolean overrideEnvThread){
OTETaskRegistration reg;
-// synchronized (newTasks) {
- boolean mainThreadWait = false;
- if(isTimeSimulated && !overrideEnvThread){
- if(mainThread != null && Thread.currentThread().equals(mainThread)){
- mainThreadWait = true;
- }
-// msInTheFuture= msInTheFuture - 1;//this makes stuff slow?
- }
- OTETask task = new OTETask(runnable, getTime() + msInTheFuture);
- task.setMain(mainThreadWait);
- reg = new OTETaskRegistration(this, task);
- if(ignoreWaits){
- try {
- task.call();
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- } else {
- try{
-// lock.lock();
- if(mainThreadWait && isTimeSimulated){
- simulatedEnvNotifyTasks.add(task);
- } else {
- tasks.add(task);
- }
- } finally {
-// lock.unlock();
- }
- doTasksHaveAnyMainThreadWaits = true;
- }
-// }
- return reg;
+ boolean mainThreadWait = false;
+ if(isTimeSimulated && !overrideEnvThread){
+ if(mainThread != null && Thread.currentThread().equals(mainThread)){
+ mainThreadWait = true;
+ }
+ }
+ OTETask task = new OTETask(runnable, getTime() + msInTheFuture, 0);
+ task.setMain(mainThreadWait);
+ reg = new OTETaskRegistration(this, task);
+ if(ignoreWaits){
+ try {
+ task.call();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } else {
+ if(mainThreadWait && isTimeSimulated){
+ simulatedEnvNotifyTasks.add(task);
+ } else {
+ tasks.add(task);
+ }
+ }
+ return reg;
}
public OTETaskRegistration scheduleWithDelay(Runnable runnable, long msInTheFuture){
@@ -315,64 +271,23 @@ public class SchedulerImpl implements Scheduler {
return reg;
}
-// void setTimerFor(OteReentrantLock lock, OteCondition condition, int milliseconds){
-// addEnvEvent(new Timeout(lock, condition), milliseconds);
-// }
-
-
-// private void addEnvEvent(Timeout timeout, long milliseconds) {
-//
-//
-//
-// }
-//
-//
-// private static class Timeout implements Runnable {
-//
-// private OteCondition condition;
-// private OteReentrantLock lock;
-//
-// public Timeout(OteReentrantLock lock, OteCondition condition) {
-// this.condition = condition;
-// this.lock = lock;
-// }
-//
-// @Override
-// public void run() {
-// try{
-// lock.lock();
-// condition.signalAll();
-// } finally {
-// lock.unlock();
-// }
-// }
-//
-// }
-
public static void main(String[] args){
final SchedulerImpl sch = new SchedulerImpl(false, DelayStrategy.sleep);
sch.scheduleAtFixedRate(new Runnable(){
long lastTimeRun = sch.getTime();
@Override
public void run() {
-// try {
-// Thread.sleep(20);
- long period = sch.getTime() - lastTimeRun;
- if(period > 21 || period < 19){
- System.out.println(period);
- System.out.println(sch.clock.tick);
- }
-// System.out.println(sch.getTime() - lastTimeRun);
- lastTimeRun = sch.getTime();
-// } catch (InterruptedException e) {
-// // TODO Auto-generated catch block
-// e.printStackTrace();
-// }
+ long period = sch.getTime() - lastTimeRun;
+ if(period > 21 || period < 19){
+ System.out.println(period);
+ System.out.println(sch.clock.tick);
+ }
+ lastTimeRun = sch.getTime();
}
}, 50.0);
long time = System.currentTimeMillis();
sch.start();
-
+
try {
Thread.sleep(10000);
System.out.println("warm up done");
@@ -380,50 +295,27 @@ public class SchedulerImpl implements Scheduler {
sch.stop();
long elapsed = System.currentTimeMillis() - time;
System.out.println(elapsed);
-// System.out.println((double)sch.getTime()/(double)elapsed);
-
+
} catch (InterruptedException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("done with main?");
}
boolean removeTask(OTETask task) {
-// System.out.println("remove " + getTime() + " " + task.toString());
boolean removed = false;
if(isTimeSimulated){
removed = wallClockScheduler.removeTask(task);
if(!removed){
-// lock.lock();
- try{
removed = simulatedEnvNotifyTasks.remove(task);
- } finally {
-// lock.unlock();
- }
}
}
if(!removed){
-// lock.lock();
- try{
removed = tasks.remove(task);
- } finally {
-// lock.unlock();
- }
-// System.out.printf("Removed Task: %s\n", task.toString());
}
if(removed && task instanceof OTETaskHeavy){
System.out.println(task.toString());
}
-// if(removed && isTimeSimulated){
-// System.out.println("failed to remove :************************************************************" + task);
-// System.out.println(task.toString());
-// }
-// System.out.println("removed task:************************************************************");
-// for(OTETask t:tasks){
-// System.out.println(t);
-// }
-// System.out.println("**************************************************************");
return removed;
}
@@ -433,26 +325,21 @@ public class SchedulerImpl implements Scheduler {
wallClockScheduler.cancelAndIgnoreWaits(ignoreWaits);
}
if(ignoreWaits){
- try{
-// lock.lock();
- for(OTETask task:tasks){
- tasks.remove(task);
- if(task.period()>0){
- task.setNextTime(getTime() + task.period());
- tasks.add(task);
- } else {
- if(!task.isComplete()){
- try {
- task.call();
- } catch (Exception e) {
- e.printStackTrace();
- }
+ for(OTETask task:tasks){
+ tasks.remove(task);
+ if(task.period()>0){
+ task.setNextTime(getTime() + task.period());
+ tasks.add(task);
+ } else {
+ if(!task.isComplete()){
+ try {
+ task.call();
+ } catch (Exception e) {
+ e.printStackTrace();
}
}
- }
- } finally {
-// lock.unlock();
- }
+ }
+ }
}
}
@@ -482,30 +369,15 @@ public class SchedulerImpl implements Scheduler {
public void setMainThread(Thread thread){
this.mainThread = thread;
-// if(mainThread != null){
-// clock.reset();
-// }
- try{
-// lock.lock();
- for(OTETask task:tasks){
- tasks.remove(task);
- if(task.period()>0){
- task.setNextTime(getTime() + task.period());
- tasks.add(task);
- } else {
- task.cancel();
- }
- }
-
-// System.out.println("set main thread task:" + tasks.size() +"************************************************************");
-// for(OTETask t:tasks){
-// System.out.println(t);
-// }
-// System.out.println("**************************************************************");
-
- } finally {
-// lock.unlock();
- }
+ for(OTETask task:tasks){
+ tasks.remove(task);
+ if(task.period()>0){
+ task.setNextTime(getTime() + task.period());
+ tasks.add(task);
+ } else {
+ task.cancel();
+ }
+ }
}
public void resetClock(){
@@ -513,8 +385,7 @@ public class SchedulerImpl implements Scheduler {
}
@Override
- public void pauseSimulated(boolean pause) {
- // TODO Auto-generated method stub
+ public synchronized void pauseSimulated(boolean pause) {
this.pauseSimulated = pause;
}
@@ -526,7 +397,5 @@ public class SchedulerImpl implements Scheduler {
public void setNoPause(boolean noPause){
this.noPause = noPause;
}
-
-
}
diff --git a/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/SortedLinkedList.java b/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/SortedLinkedList.java
deleted file mode 100644
index f08811f9842..00000000000
--- a/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/SortedLinkedList.java
+++ /dev/null
@@ -1,386 +0,0 @@
-package org.eclipse.ote.scheduler;
-
-import java.lang.reflect.Array;
-import java.util.ArrayDeque;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-
-public class SortedLinkedList<T extends Comparable> implements List<T>{
-
- private List<T> added = new ArrayList<>();
- private List<Object> deleted = new ArrayList<>();
-
- private ArrayDeque<Node<T>> pool;
-
- private MyIterator it;
-
- private Node<T> head;
- private Node<T> tail;
-
- public SortedLinkedList() {
- pool = new ArrayDeque<>();
- for(int i = 0; i < 8; i++){
- pool.push(new Node<T>());
- }
- it = new MyIterator(this);
- }
-
- @Override
- public int size() {
- Node<T> node = head;
- int size = 0;
- while(node != null){
- size++;
- node = node.nextNode;
- }
- return size;
- }
-
- @Override
- public synchronized boolean isEmpty() {
- updateList();
-// if(!added.isEmpty()){
-// return false;
-// } else {
- return head == null;
-// }
- }
-
- @Override
- public boolean contains(Object o) {
- Node<T> node = head;
- while(node != null){
- if (o.equals(node)){
- return true;
- } else {
- node = node.nextNode;
- }
- }
- return false;
- }
-
- @Override
- public synchronized Iterator<T> iterator() {
-
- updateList();
-
- it.currentNode = null;
- return it;
- }
-
- private void updateList(){
- for(int i = 0; i < deleted.size(); i++){
- removeLocal(deleted.get(i));
- }
- deleted.clear();
- for(int i = 0; i < added.size(); i++){
- addLocal(added.get(i));
- }
- added.clear();
- }
-
- @Override
- public Object[] toArray() {
- Object[] objs = new Object[size()];
- Node<T> node = head;
- int i = 0;
- while(node != null && i < objs.length){
- objs[i] = node.object;
- }
- return objs;
- }
-
- @SuppressWarnings({ "unchecked", "hiding" })
- @Override
- public <T> T[] toArray(T[] a) {
- int size = size();
- if(a.length != size){
- a = (T[])Array.newInstance(a.getClass(), size);
- }
- Node node = head;
- int i = 0;
- while(node != null && i < a.length){
- a[i] = (T)node.object;
- }
- return a;
- }
-
- @Override
- public synchronized boolean add(T e) {
- return added.add(e);
- }
-
- public boolean addLocal(T e) {
- Node node = head;
- boolean added = false;
- Node<T> newNode;
- if(!pool.isEmpty()){
- newNode = pool.pop();
- } else {
- newNode = new Node<T>();
- }
- newNode.object = e;
- if(head == null){
- head = newNode;
- tail = newNode;
- } else {
- while(node != null){
- if(e.compareTo(node.object) < 0){
- Node before = node.previousNode;
- Node after = node;
- newNode.previousNode = before;
- newNode.nextNode = node;
- if(before != null){
- before.nextNode = newNode;
- } else {
- head = newNode;
- }
- after.previousNode = newNode;
- added = true;
- break;
- }
- node = node.nextNode;
- }
- if(!added){
- newNode.previousNode = tail;
- tail.nextNode = newNode;
- tail = newNode;
- }
- }
- return true;
- }
-
- @Override
- public synchronized boolean remove(Object o) {
- deleted.add(o);
- return contains(o);
- }
-
- public boolean removeLocal(Object o) {
- Node node = head;
- while(node != null){
- if(o.equals(node.object)){
- if(node == head){
- if(node.nextNode != null){
- node.nextNode.previousNode = null;
- head = node.nextNode;
- } else {
- head = null;
- tail = null;
- }
- } else if(node == tail){
- node.previousNode.nextNode = null;
- tail = node.previousNode;
- } else {
- node.previousNode.nextNode = node.nextNode;
- node.nextNode.previousNode = node.previousNode;
- }
- node.nextNode = null;
- node.previousNode = null;
- node.object = null;
- pool.push(node);
- return true;
- }
- node = node.nextNode;
- }
- return false;
- }
-
- @Override
- public boolean containsAll(Collection<?> c) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean addAll(Collection<? extends T> c) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean addAll(int index, Collection<? extends T> c) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean removeAll(Collection<?> c) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean retainAll(Collection<?> c) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public void clear() {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public T get(int index) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public T set(int index, T element) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public void add(int index, T element) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public T remove(int index) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public int indexOf(Object o) {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- public int lastIndexOf(Object o) {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- public ListIterator<T> listIterator() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public ListIterator<T> listIterator(int index) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public List<T> subList(int fromIndex, int toIndex) {
- // TODO Auto-generated method stub
- return null;
- }
-
- private static class Node<T> {
-
- T object;
- Node<T> previousNode;
- Node<T> nextNode;
-
- public Node(){
- previousNode = null;
- nextNode = null;
- }
-
- }
-
- private static class MyIterator<T extends Comparable<T>> implements Iterator<T> {
-
- Node<T> currentNode;
- private SortedLinkedList<T> parent;
-
- public MyIterator(SortedLinkedList<T> parent) {
- this.parent = parent;
- }
-
- @Override
- public boolean hasNext() {
- if(currentNode == null && parent.head != null){
- return true;
- } else if (currentNode != null && currentNode.nextNode != null){
- return true;
- } else {
- return false;
- }
- }
-
- @Override
- public T next() {
- if(currentNode == null){
- currentNode = parent.head;
- } else {
- currentNode = currentNode.nextNode;
- }
- return currentNode.object;
- }
-
- @Override
- public void remove(){
-// Node toRemove = v;
-// currentNode = currentNode.previousNode;
- parent.remove(currentNode.object);
- }
-
- }
-
- public static void main(String[] args){
- SortedLinkedList<Integer> list = new SortedLinkedList<>();
-
- if(list.iterator().hasNext()){
- System.out.println("no");
- }
-
- list.add(1);
- list.print();
- list.add(30);
- list.print();
- list.add(35);
- list.print();
-
- list.add(3);
- list.print();
-
- list.add(10);
- list.print();
-
- list.add(23);
- list.print();
-
- list.add(350);
- list.print();
-
- list.add(200);
- list.print();
-
- list.add(31);
- list.print();
-
- list.add(30);
- list.print();
-
- }
-
- public void print() {
- for(T t:this){
- System.out.printf("%s, ", t.toString());
- }
-
- System.out.println();
- Node node = tail;
- while(node != null){
- System.out.printf("%s, ", node.object.toString());
- node = node.previousNode;
- }
- System.out.println();
-
- }
-
- }
diff --git a/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/SortedLinkedListCopyOnWrite.java b/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/SortedLinkedListCopyOnWrite.java
index c5a4f2b2c05..19092946595 100644
--- a/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/SortedLinkedListCopyOnWrite.java
+++ b/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/SortedLinkedListCopyOnWrite.java
@@ -8,7 +8,6 @@ import java.util.concurrent.atomic.AtomicReference;
public class SortedLinkedListCopyOnWrite<T extends Comparable<T>> implements List<T>{
-
private ObjectPool<MyInnerIterator<T>> itpool;
private ObjectPool<Node<T>> nodePool;
private ObjectPool<LinkedList<T>> pool;
@@ -17,10 +16,7 @@ public class SortedLinkedListCopyOnWrite<T extends Comparable<T>> implements Lis
private AtomicReference<LinkedList<T>> data;
private volatile int refCount;
- private int listCount = 4;
private boolean debug = false;
-
-
@SuppressWarnings({ "rawtypes", "unchecked" })
public SortedLinkedListCopyOnWrite() {
@@ -44,7 +40,6 @@ public class SortedLinkedListCopyOnWrite<T extends Comparable<T>> implements Lis
itpool = new ObjectPool( new Create<MyInnerIterator<T>>(){
@Override
public MyInnerIterator<T> create() {
- // TODO Auto-generated method stub
return new MyInnerIterator<>();
}
@@ -92,39 +87,6 @@ public class SortedLinkedListCopyOnWrite<T extends Comparable<T>> implements Lis
inUseItems.clear();
}
-// LinkedList<T> getList(){
-// poolLock.lock();
-// LinkedList<T> newNode;
-// try{
-// if(!pool.isEmpty()){
-// newNode = pool.pop();
-// } else {
-// listCount++;
-// System.out.printf("NEW LIST %d *****************************************************************\n", listCount);
-// newNode = new LinkedList<>(nodePool);
-// }
-// } finally {
-// poolLock.unlock();
-// }
-// return newNode;
-// }
-//
-// private void pushList(LinkedList<T> node){
-// poolLock.lock();
-// try{
-// pool.push(node);
-// } finally {
-// poolLock.unlock();
-// }
-// }
-
- private synchronized LinkedList<T> cloneList(){
-
- return null;
- }
-
-
-
@Override
public int size() {
return data.get().size();
@@ -147,18 +109,6 @@ public class SortedLinkedListCopyOnWrite<T extends Comparable<T>> implements Lis
}
public synchronized void doneWithIterator(MyInnerIterator<T> it){
- //do something smart to recoup nodes from it if the data has changed
-
-// if(!data.get().iterator().equals(it)){
-//// LinkedList<T> list = it.parent;
-//// list.clear();
-//// pool.push(list);
-// System.out.println("the iterator has changed so the old array is crap "+ this.hashCode());
-//
-// }
-// else {
-// System.out.println("same iterator... no changes " + this.hashCode());
-// }
inUseItems.clear();
pool.fillInUseItems(inUseItems);
for(int i = 0; i < inUseItems.size(); i++){
@@ -169,47 +119,25 @@ public class SortedLinkedListCopyOnWrite<T extends Comparable<T>> implements Lis
}
}
itpool.push(it);
-// refCount--;
}
@Override
public Object[] toArray() {
-// Object[] objs = new Object[size()];
-// Node<T> node = head;
-// int i = 0;
-// while(node != null && i < objs.length){
-// objs[i] = node.object;
-// }
- return null;//objs;
+ return null;
}
- @SuppressWarnings({ "unchecked", "hiding" })
+ @SuppressWarnings("hiding")
@Override
public <T> T[] toArray(T[] a) {
-// int size = size();
-// if(a.length != size){
-// a = (T[])Array.newInstance(a.getClass(), size);
-// }
-// Node node = head;
-// int i = 0;
-// while(node != null && i < a.length){
-// a[i] = (T)node.object;
-// }
- return null;//a;
+ return null;
}
public synchronized boolean add(T e) {
-// int currentRefcount = refCount;
LinkedList<T> currentList = data.get();
LinkedList<T> newList = copy(currentList, pool.get());
boolean returnVal = newList.addLocal(e);
data.set(newList);
currentList.setCurrent(false);
-// if(currentRefcount == refCount){
-
-// currentList.clear();
-// pool.push(currentList);
-// }
return returnVal;
}
@@ -238,31 +166,26 @@ public class SortedLinkedListCopyOnWrite<T extends Comparable<T>> implements Lis
@Override
public boolean containsAll(Collection<?> c) {
- // TODO Auto-generated method stub
return false;
}
@Override
public boolean addAll(Collection<? extends T> c) {
- // TODO Auto-generated method stub
return false;
}
@Override
public boolean addAll(int index, Collection<? extends T> c) {
- // TODO Auto-generated method stub
return false;
}
@Override
public boolean removeAll(Collection<?> c) {
- // TODO Auto-generated method stub
return false;
}
@Override
public boolean retainAll(Collection<?> c) {
- // TODO Auto-generated method stub
return false;
}
@@ -273,61 +196,51 @@ public class SortedLinkedListCopyOnWrite<T extends Comparable<T>> implements Lis
@Override
public T get(int index) {
- // TODO Auto-generated method stub
return null;
}
@Override
public T set(int index, T element) {
- // TODO Auto-generated method stub
return null;
}
@Override
public void add(int index, T element) {
- // TODO Auto-generated method stub
-
}
@Override
public T remove(int index) {
- // TODO Auto-generated method stub
return null;
}
@Override
public int indexOf(Object o) {
- // TODO Auto-generated method stub
return 0;
}
@Override
public int lastIndexOf(Object o) {
- // TODO Auto-generated method stub
return 0;
}
@Override
public ListIterator<T> listIterator() {
- // TODO Auto-generated method stub
return null;
}
@Override
public ListIterator<T> listIterator(int index) {
- // TODO Auto-generated method stub
return null;
}
@Override
public List<T> subList(int fromIndex, int toIndex) {
- // TODO Auto-generated method stub
return null;
}
public void print() {
- LinkedList list = data.get();
- Node node = list.head;
+ LinkedList<T> list = data.get();
+ Node<T> node = list.head;
while(node != null){
System.out.printf("%s, ", node.object.toString());
node = node.nextNode;
diff --git a/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/SortedOnInsertList.java b/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/SortedOnInsertList.java
deleted file mode 100644
index c7350a9d440..00000000000
--- a/plugins/org.eclipse.ote.scheduler/src/org/eclipse/ote/scheduler/SortedOnInsertList.java
+++ /dev/null
@@ -1,250 +0,0 @@
-package org.eclipse.ote.scheduler;
-
-import java.lang.reflect.Array;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-public class SortedOnInsertList<T extends Comparable<T>> implements Iterable<T> {
-
- int first = 0;
- int last = 0;
- int count = 0;
- private T[] data;
- List<T> arrayList;
-
- private NoNewIterator it;
- private Class<T> clazz;
-
- @SuppressWarnings("unchecked")
- public SortedOnInsertList(Class<T> clazz){
- this.clazz = clazz;
- data = (T[]) Array.newInstance(clazz, 8);
- it = new NoNewIterator();
- arrayList = new ArrayList<>();
- }
-
- public boolean add(T task){
- int index = findClosestGreaterThan(task);
- if(index >= data.length){
- compress();
- index = findClosestGreaterThan(task);
- }
- if(index >= data.length){
- growArray();
- }
- if(data[index] == null){
- data[index]=task;
- } else if(isSpaceToLeft(index)){//is there a space to the left
- data[index-1]=task;
- } else {
- if(!canShiftRight(index)){
- compress();
- index = findClosestGreaterThan(task);
- if(!canShiftRight(index)){
- growArray();
- }
- }
- shiftRight(index);
- data[index] = task;
- }
- return true;
- }
-
- private void compress() {
- for(int i = 0; i < data.length; i++){
- if(data[i] == null){
- for(int j = i+1; j < data.length; j++){
- if(data[j] != null){
- data[i] = data[j];
- data[j] = null;
- break;
- }
- }
- }
- }
- }
-
- private void shiftRight(int index) {
- int firstNull = index+1;
- for(;firstNull < data.length;firstNull++){
- if(data[firstNull] == null){
- break;
- }
- }
- for(int i = firstNull; i > index; i--){
- data[i] = data[i-1];
- }
- data[index] = null;
- }
-
- private void growArray() {
- @SuppressWarnings("unchecked")
- T[] newTasks = (T[]) Array.newInstance(clazz, data.length + 8);
- System.arraycopy(data, 0, newTasks, 0, data.length);
- data = newTasks;
- }
-
- private boolean canShiftRight(int index) {
- for(int i = index+1; i < data.length; i++){
- if(data[i] == null){
- return true;
- }
- }
- return false;
- }
-
- private boolean isSpaceToLeft(int index) {
- if(index > 0 && data[index-1] == null){
- return true;
- }
- return false;
- }
-
- private int findClosestGreaterThan(T task){
- int i = 0;
- int lastItem = 0;
- for(; i < data.length; i++){
- if(data[i] != null){
- lastItem = i;
- if(data[i].compareTo(task) > 0){
- return i;
- }
- }
- }
- return lastItem+1;
- }
-
- public boolean remove(T task){
- for(int i = 0; i < data.length; i++){
- if(data[i] != null){
- if(data[i].equals(task)){
- data[i] = null;
- return true;
- }
- }
- }
- return false;
- }
-
- @Override
- public Iterator<T> iterator() {
- it.reset();
- return it;
- }
-
- public static void main(String[] args){
- SortedOnInsertList<Integer> list = new SortedOnInsertList<>(Integer.class);
-
- if(list.iterator().hasNext()){
- System.out.println("");
- }
-
- list.add(1);
- list.print();
- list.add(30);
- list.print();
- list.add(35);
- list.print();
-
- list.add(3);
- list.print();
-
- list.add(10);
- list.print();
-
- list.add(23);
- list.print();
-
- list.add(350);
- list.print();
-
- list.add(200);
- list.print();
-
- list.add(31);
- list.print();
-
- list.add(30);
- list.print();
-
- }
-
- private void print() {
- for(T t:this){
- System.out.printf("%s, ", t.toString());
- }
- System.out.println();
- }
-
- private class NoNewIterator implements Iterator<T> {
-
- private int current;
-
- public NoNewIterator() {
-
- }
-
- @Override
- public boolean hasNext() {
- for(int i = current+1; i < SortedOnInsertList.this.data.length; i++){
- if(SortedOnInsertList.this.data[i] != null){
- return true;
- }
- }
- return false;
- }
-
- public void reset() {
- current = -1;
- }
-
- @Override
- public T next() {
- for(int i = current+1; i < SortedOnInsertList.this.data.length; i++){
- if(SortedOnInsertList.this.data[i] != null){
- current = i;
- return SortedOnInsertList.this.data[i];
- }
- }
- return null;
- }
-
- @Override
- public void remove(){
- SortedOnInsertList.this.data[current] = null;
- }
-
- }
-
- public int size() {
- int size = 0;
- for(int i = 0; i < data.length; i++){
- if(data[i] != null){
- size++;
- }
- }
- return size;
- }
-
- public boolean isEmpty() {
- for(int i = 0; i < data.length; i++){
- if(data[i] != null){
- return false;
- }
- }
- return true;
- }
-
- public void addToQueue(T task) {
- arrayList.add(task);
- }
-
- public void flushAddQueue(){
- for(int i = 0; i < arrayList.size(); i++){
- add(arrayList.get(i));
- }
- arrayList.clear();
- }
-
-}

Back to the top