--- /dev/null
+// $Id:\r
+// FORESTER -- software libraries and applications\r
+// for evolutionary biology research and applications.\r
+//\r
+// Copyright (C) 2008-2012 Christian M. Zmasek\r
+// Copyright (C) 2008-2012 Sanford Burnham Medical Research Institute\r
+// All rights reserved\r
+//\r
+// This library is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU Lesser General Public\r
+// License as published by the Free Software Foundation; either\r
+// version 2.1 of the License, or (at your option) any later version.\r
+//\r
+// This library is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+// Lesser General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU Lesser General Public\r
+// License along with this library; if not, write to the Free Software\r
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
+//\r
+// Contact: phylosoft @ gmail . com\r
+// WWW: www.phylosoft.org/forester\r
+\r
+package org.forester.archaeopteryx.tools;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+public class ProcessPool {\r
+\r
+ final static private ArrayList<ProcessRunning> _processes = new ArrayList<ProcessRunning>();\r
+\r
+ public synchronized ProcessRunning getProcessByIndex( final int i ) {\r
+ return getProcesses().get( i );\r
+ }\r
+\r
+ public synchronized int size() {\r
+ return getProcesses().size();\r
+ }\r
+\r
+ public synchronized ProcessRunning getProcessById( final int id ) {\r
+ for( final ProcessRunning p : getProcesses() ) {\r
+ if ( p.getId() == id ) {\r
+ return p;\r
+ }\r
+ }\r
+ return null;\r
+ }\r
+\r
+ public synchronized int addProcess( final String name ) {\r
+ final ProcessRunning p = ProcessRunning.createInstance( name );\r
+ final int id = p.getId();\r
+ if ( getProcessById( id ) != null ) {\r
+ throw new IllegalStateException( "process with id " + id + "already exists" );\r
+ }\r
+ getProcesses().add( p );\r
+ return id;\r
+ }\r
+\r
+ public synchronized boolean removeProcess( final int id ) {\r
+ final int i = getProcessIndexById( id );\r
+ if ( i >= 0 ) {\r
+ getProcesses().remove( i );\r
+ return true;\r
+ }\r
+ return false;\r
+ }\r
+\r
+ private synchronized int getProcessIndexById( final int id ) {\r
+ final ProcessRunning p = getProcessById( id );\r
+ if ( p != null ) {\r
+ return p.getId();\r
+ }\r
+ return -1;\r
+ }\r
+\r
+ private synchronized List<ProcessRunning> getProcesses() {\r
+ return _processes;\r
+ }\r
+}\r
--- /dev/null
+// $Id:\r
+// FORESTER -- software libraries and applications\r
+// for evolutionary biology research and applications.\r
+//\r
+// Copyright (C) 2008-2012 Christian M. Zmasek\r
+// Copyright (C) 2008-2012 Sanford Burnham Medical Research Institute\r
+// All rights reserved\r
+//\r
+// This library is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU Lesser General Public\r
+// License as published by the Free Software Foundation; either\r
+// version 2.1 of the License, or (at your option) any later version.\r
+//\r
+// This library is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+// Lesser General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU Lesser General Public\r
+// License along with this library; if not, write to the Free Software\r
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
+//\r
+// Contact: phylosoft @ gmail . com\r
+// WWW: www.phylosoft.org/forester\r
+\r
+package org.forester.archaeopteryx.tools;\r
+\r
+import java.text.SimpleDateFormat;\r
+import java.util.Calendar;\r
+\r
+final class ProcessRunning {\r
+\r
+ private static int count = 0;\r
+ final private int _id;\r
+ final private String _name;\r
+ final private String _start;\r
+\r
+ int getId() {\r
+ return _id;\r
+ }\r
+ \r
+ String getName() {\r
+ return _name;\r
+ }\r
+ \r
+ String getStart() {\r
+ return _start;\r
+ }\r
+ \r
+ public String toString() {\r
+ return getName() + " [id=" + getId() + "] [start=" + getStart() + "]";\r
+ }\r
+ \r
+ synchronized static ProcessRunning createInstance( final String name ) {\r
+ final Calendar cal = Calendar.getInstance();\r
+ final SimpleDateFormat sdf = new SimpleDateFormat( "HH:mm:ss" );\r
+ return new ProcessRunning( count++, name, sdf.format( cal.getTime() ) );\r
+ }\r
+ \r
+ private ProcessRunning( final int id, final String name, final String start ) {\r
+ _id = id;\r
+ _name = name;\r
+ _start = start; \r
+ }\r
+\r
+}\r