+/*
+ * Copyright (c) 2014 Cable Television Laboratories, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
package org.pcmm.concurrent;
import java.util.concurrent.Callable;
/**
- *
+ *
*/
public interface IWorker extends Runnable {
/**
* defines the task to be performed by this worker
- *
+ *
* @param c
*/
void task(Callable<?> c);
/**
* defines wait time before start working on the task
- *
+ *
* @param t
*/
void shouldWait(int t);
-/**
- *
+/*
+ * Copyright (c) 2014 Cable Television Laboratories, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
*/
+
package org.pcmm.concurrent;
import org.pcmm.base.IAdapter;
/**
- *
+ *
*/
public interface IWorkerPool extends IAdapter<IWorker> {
// handles 32 workers
/**
* schedules a worker for beginning its task after t milliseconds.
- *
+ *
* @param worker
* : the worker
* @param t
/**
* schedules a worker for immediate execution.
- *
+ *
* @param worker
* : the worker
* @return the id of the worker (PID) to be used for killing the worker if
/**
* kills the worker with the specified pid
- *
+ *
* @param pid
*/
void sendKillSignal(int pid);
-/**
- *
+/*
+ * Copyright (c) 2014 Cable Television Laboratories, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
*/
+
package org.pcmm.concurrent.impl;
import java.util.concurrent.Callable;
import org.slf4j.LoggerFactory;
/**
- *
+ *
*/
public class Worker implements IWorker {
/*
* (non-Javadoc)
- *
+ *
* @see java.lang.Runnable#run()
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see org.pcmm.threading.IWorker#task(java.util.concurrent.Callable)
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see org.pcmm.threading.IWorker#shouldWait(int)
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see org.pcmm.threading.IWorker#done()
*/
@Override
+/*
+ * Copyright (c) 2014 Cable Television Laboratories, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
package org.pcmm.concurrent.impl;
import java.lang.ref.WeakReference;
public class WorkerPool implements IWorkerPool {
/**
- *
+ *
*/
private Map<Integer, WeakReference<IWorker>> workersMap;
/*
* (non-Javadoc)
- *
+ *
* @see org.pcmm.threading.IWorkerPool#schedule(org.pcmm.threading.IWorker,
* int)
*/
/*
* (non-Javadoc)
- *
+ *
* @see
* org.pcmm.concurrent.IWorkerPool#schedule(org.pcmm.concurrent.IWorker)
*/
/*
* (non-Javadoc)
- *
+ *
* @see org.pcmm.concurrent.IWorkerPool#sendKillSignal(int)
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see org.pcmm.threading.IWorkerPool#killAll()
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see org.pcmm.threading.IWorkerPool#recycle()
*/
@Override