|
| 1 | +package com.swiftmq.client.thread; |
| 2 | + |
| 3 | +import com.swiftmq.swiftlet.SwiftletManager; |
| 4 | +import com.swiftmq.swiftlet.threadpool.AsyncTask; |
| 5 | +import com.swiftmq.swiftlet.threadpool.ThreadPool; |
| 6 | +import com.swiftmq.swiftlet.threadpool.ThreadpoolSwiftlet; |
| 7 | +import com.swiftmq.swiftlet.threadpool.event.FreezeCompletionListener; |
| 8 | + |
| 9 | +public class IVMTaskScheduler implements ThreadPool { |
| 10 | + |
| 11 | + ThreadpoolSwiftlet threadpoolSwiftlet = null; |
| 12 | + |
| 13 | + public IVMTaskScheduler() { |
| 14 | + threadpoolSwiftlet = (ThreadpoolSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$threadpool"); |
| 15 | + if (threadpoolSwiftlet == null) |
| 16 | + System.err.println("[" + this + "] Failed to get ThreadpoolSwiftlet"); |
| 17 | + else |
| 18 | + System.out.println("[" + this + "] App uses virtual threads, scheduled in: adhocvirtual"); |
| 19 | + } |
| 20 | + |
| 21 | + /** |
| 22 | + * Closes the pool. |
| 23 | + * Internal use only. |
| 24 | + */ |
| 25 | + @Override |
| 26 | + public void close() { |
| 27 | + |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * Returns the pool name. |
| 32 | + * |
| 33 | + * @return pool name. |
| 34 | + */ |
| 35 | + @Override |
| 36 | + public String getPoolName() { |
| 37 | + return toString(); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Returns the number of currently idling threads. |
| 42 | + * Used from management tools only. |
| 43 | + * |
| 44 | + * @return number of idling threads. |
| 45 | + */ |
| 46 | + @Override |
| 47 | + public int getNumberIdlingThreads() { |
| 48 | + return 0; |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * Returns the number of currently running threads. |
| 53 | + * Used from management tools only. |
| 54 | + * |
| 55 | + * @return number of running threads. |
| 56 | + */ |
| 57 | + @Override |
| 58 | + public int getNumberRunningThreads() { |
| 59 | + return 0; |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Dispatch a task into the pool. |
| 64 | + * |
| 65 | + * @param asyncTask the task to dispatch. |
| 66 | + */ |
| 67 | + @Override |
| 68 | + public void dispatchTask(AsyncTask asyncTask) { |
| 69 | + threadpoolSwiftlet.runAsync(asyncTask, true); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * Freezes this pool. That is, the current running tasks are completed but |
| 74 | + * no further tasks will be scheduled until unfreeze() is called. It is possible |
| 75 | + * to dispatch tasks during freeze. However, these will be executed after unfreeze() |
| 76 | + * is called. |
| 77 | + * |
| 78 | + * @param listener will be called when the pool is freezed. |
| 79 | + */ |
| 80 | + @Override |
| 81 | + public void freeze(FreezeCompletionListener listener) { |
| 82 | + |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * Unfreezes this pool. |
| 87 | + */ |
| 88 | + @Override |
| 89 | + public void unfreeze() { |
| 90 | + |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * Stops the pool. |
| 95 | + * Internal use only. |
| 96 | + */ |
| 97 | + @Override |
| 98 | + public void stop() { |
| 99 | + |
| 100 | + } |
| 101 | + |
| 102 | + @Override |
| 103 | + public String toString() { |
| 104 | + return IVMTaskScheduler.class.getSimpleName(); |
| 105 | + } |
| 106 | +} |
0 commit comments