Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.threadpool; |
| 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.Collection; |
| 5 | import java.util.HashMap; |
| 6 | import java.util.Map; |
| 7 | import java.util.concurrent.Executors; |
| 8 | import java.util.concurrent.ScheduledExecutorService; |
| 9 | |
| 10 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 11 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
| 12 | import net.floodlightcontroller.core.module.IFloodlightModule; |
| 13 | import net.floodlightcontroller.core.module.IFloodlightService; |
| 14 | |
| 15 | public class ThreadPool implements IThreadPoolService, IFloodlightModule { |
| 16 | protected ScheduledExecutorService executor = null; |
| 17 | |
| 18 | // IThreadPoolService |
| 19 | |
| 20 | @Override |
| 21 | public ScheduledExecutorService getScheduledExecutor() { |
| 22 | return executor; |
| 23 | } |
| 24 | |
| 25 | // IFloodlightModule |
| 26 | |
| 27 | @Override |
| 28 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
| 29 | Collection<Class<? extends IFloodlightService>> l = |
| 30 | new ArrayList<Class<? extends IFloodlightService>>(); |
| 31 | l.add(IThreadPoolService.class); |
| 32 | return l; |
| 33 | } |
| 34 | |
| 35 | @Override |
| 36 | public Map<Class<? extends IFloodlightService>, IFloodlightService> |
| 37 | getServiceImpls() { |
| 38 | Map<Class<? extends IFloodlightService>, |
| 39 | IFloodlightService> m = |
| 40 | new HashMap<Class<? extends IFloodlightService>, |
| 41 | IFloodlightService>(); |
| 42 | m.put(IThreadPoolService.class, this); |
| 43 | // We are the class that implements the service |
| 44 | return m; |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public Collection<Class<? extends IFloodlightService>> |
| 49 | getModuleDependencies() { |
| 50 | // No dependencies |
| 51 | return null; |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public void init(FloodlightModuleContext context) |
| 56 | throws FloodlightModuleException { |
| 57 | executor = Executors.newScheduledThreadPool(15); |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public void startUp(FloodlightModuleContext context) { |
| 62 | // no-op |
| 63 | } |
| 64 | } |