r335 - in trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs: . runner ui/handler
Author: tchemit Date: 2008-04-04 19:32:54 +0000 (Fri, 04 Apr 2008) New Revision: 335 Added: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/runner/ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/runner/VCSActionManager.java trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/runner/VCSActionThread.java Removed: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSActionManager.java Modified: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/handler/AbstractConfirmUIHandler.java Log: add runner package Deleted: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSActionManager.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSActionManager.java 2008-04-04 19:32:29 UTC (rev 334) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSActionManager.java 2008-04-04 19:32:54 UTC (rev 335) @@ -1,157 +0,0 @@ -/** - * # #% Copyright (C) 2008 Code Lutin, Tony Chemit - * This program is free software; you - * can redistribute it and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. This program is - * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. You - * should have received a copy of the GNU General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - * - Suite 330, Boston, MA 02111-1307, USA. - * # #% - */ -package org.codelutin.vcs; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import static org.codelutin.i18n.I18n._; - -import java.util.Date; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.PriorityBlockingQueue; - -/** - * Manager used to fired vcs actions - * <p/> - * use a {@link org.codelutin.vcs.VCSActionManager.VCSActionThread}. - * - * @author chemit - */ -public class VCSActionManager { - - /** vcs actions runner thread */ - protected VCSActionThread thread; - - /** queue */ - protected PriorityBlockingQueue<QueueItem> queue; - - public boolean add(VCSAction action, VCSFileState[] states) { - QueueItem queueItem = new QueueItem(action, states); - return queue.add(queueItem); - } - - public VCSActionManager(VCSHandler handler) { - queue = new PriorityBlockingQueue<QueueItem>(1024); - thread = new VCSActionThread(handler, queue); - thread.start(); - } - - - /** @author chemit */ - public static class VCSActionThread extends Thread implements VCSHandlerEventListener { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - static private Log log = LogFactory.getLog(VCSActionThread.class); - - /** queue */ - protected BlockingQueue<QueueItem> queue; - - /** handler to use for vcs operations */ - protected VCSHandler handler; - - public VCSActionThread(VCSHandler handler, BlockingQueue<QueueItem> queue) { - super("VCSAction Thread [" + handler + "]"); - this.handler = handler; - this.queue = queue; - this.handler.addVCSHandlerEventListener(this); - } - - @Override - public void run() { - log.info("Start " + getName() + " at " + new Date()); - boolean run = true; - QueueItem item = null; - try { - while (run) { - // item qui sert a faire la simulation courante - - log.info("waiting for action..."); - item = queue.take(); - if (item.getAction() == null) { - // this is a special case to stop thread - run = false; - continue; - } - log.info("Just take " + item); - } - } - catch (Throwable eee) { - if (log.isWarnEnabled()) { - log.warn(_("lutinvcs.error.thread.action", item), eee); - } - } - log.info("Stop " + getName() + " at " + new Date()); - } - - - public void init(VCSHandlerEvent event) { - } - - public void open(VCSHandlerEvent event) { - } - - public void close(VCSHandlerEvent event) { - - handler.removeVCSHandlerEventListener(this); - if (!queue.isEmpty()) { - queue.clear(); - } - queue.add(new QueueItem(null, new VCSFileState[0])); - } - } - - public static class QueueItem implements Comparable<QueueItem> { - - protected long time; - protected VCSFileState[] states; - protected VCSAction action; - - - public QueueItem(VCSAction action, VCSFileState[] states) { - this.time = System.nanoTime(); - this.states = states; - this.action = action; - } - - public VCSAction getAction() { - return action; - } - - public VCSFileState[] getStates() { - return states; - } - - @Override - public boolean equals(Object o) { - return this == o || o instanceof QueueItem && time == ((QueueItem) o).time; - } - - @Override - public int hashCode() { - return (int) (time ^ (time >>> 32)); - } - - @Override - public String toString() { - return super.toString() + ", time:" + time + ", action:" + action + ", size:" + (states == null ? 0 : states.length); - } - - public int compareTo(QueueItem o) { - return time == o.time ? 0 : time > o.time ? 1 : -1; - } - } - - -} Copied: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/runner/VCSActionManager.java (from rev 331, trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSActionManager.java) =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/runner/VCSActionManager.java (rev 0) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/runner/VCSActionManager.java 2008-04-04 19:32:54 UTC (rev 335) @@ -0,0 +1,110 @@ +/** + * # #% Copyright (C) 2008 Code Lutin, Tony Chemit + * This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * # #% + */ +package org.codelutin.vcs.runner; + +import org.codelutin.vcs.VCSAction; +import org.codelutin.vcs.VCSFileState; +import org.codelutin.vcs.VCSHandler; +import org.codelutin.vcs.VCSHandlerEvent; +import org.codelutin.vcs.VCSHandlerEventListener; + +import java.util.concurrent.PriorityBlockingQueue; + +/** + * Manager used to fired vcs actions + * <p/> + * use a {@link org.codelutin.vcs.runner.VCSActionThread}. + * + * @author chemit + */ +public class VCSActionManager implements VCSHandlerEventListener { + + /** special item to add in queue to stop the thread */ + protected static final QueueItem STOP_ITEM = new QueueItem(null, new VCSFileState[0]); + + /** vcs actions runner thread */ + protected VCSActionThread thread; + + /** queue */ + protected PriorityBlockingQueue<QueueItem> queue; + + public VCSActionManager(VCSHandler handler) { + queue = new PriorityBlockingQueue<QueueItem>(1024); + thread = new VCSActionThread(handler, queue); + handler.addVCSHandlerEventListener(this); + } + + public boolean add(VCSAction action, VCSFileState[] states) { + QueueItem queueItem = new QueueItem(action, states); + return queue.add(queueItem); + } + + public void init(VCSHandlerEvent event) { + } + + public void open(VCSHandlerEvent event) { + thread.start(); + } + + public void close(VCSHandlerEvent event) { + thread.handler.removeVCSHandlerEventListener(this); + if (!queue.isEmpty()) { + queue.clear(); + } + queue.add(VCSActionManager.STOP_ITEM); + } + + /** @author chemit */ + public static class QueueItem implements Comparable<QueueItem> { + + protected long time; + protected VCSFileState[] states; + protected VCSAction action; + + + public QueueItem(VCSAction action, VCSFileState[] states) { + this.time = System.nanoTime(); + this.states = states; + this.action = action; + } + + public VCSAction getAction() { + return action; + } + + public VCSFileState[] getStates() { + return states; + } + + @Override + public boolean equals(Object o) { + return this == o || o instanceof QueueItem && time == ((QueueItem) o).time; + } + + @Override + public int hashCode() { + return (int) (time ^ (time >>> 32)); + } + + @Override + public String toString() { + return super.toString() + ", time:" + time + ", action:" + action + ", size:" + (states == null ? 0 : states.length); + } + + public int compareTo(QueueItem o) { + return time == o.time ? 0 : time > o.time ? 1 : -1; + } + } +} Added: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/runner/VCSActionThread.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/runner/VCSActionThread.java (rev 0) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/runner/VCSActionThread.java 2008-04-04 19:32:54 UTC (rev 335) @@ -0,0 +1,97 @@ +/** + * # #% Copyright (C) 2008 Code Lutin, Tony Chemit + * This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * # #% + */ +package org.codelutin.vcs.runner; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import static org.codelutin.i18n.I18n._; +import org.codelutin.vcs.VCSHandler; + +import java.util.Date; +import java.util.concurrent.BlockingQueue; + +/** @author chemit */ +public class VCSActionThread extends Thread { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(VCSActionThread.class); + + /** queue */ + protected BlockingQueue<VCSActionManager.QueueItem> queue; + + /** handler to use for vcs operations */ + protected VCSHandler handler; + + public VCSActionThread(VCSHandler handler, BlockingQueue<VCSActionManager.QueueItem> queue) { + super("VCSAction Thread [" + handler + "]"); + this.handler = handler; + this.queue = queue; + } + + @Override + public void run() { + log.info("Start " + getName() + " at " + new Date()); + boolean run = true; + VCSActionManager.QueueItem item = null; + try { + while (run) { + // item qui sert a faire la simulation courante + + log.info("waiting for action..."); + item = queue.take(); + if (item.getAction() == null) { + // this is a special case to stop thread + run = false; + continue; + } + doAction(item); + } + } + catch (Throwable eee) { + if (log.isWarnEnabled()) { + log.warn(_("lutinvcs.error.thread.action", item), eee); + } + } + log.info("Stop " + getName() + " at " + new Date()); + } + + protected void doAction(VCSActionManager.QueueItem item) { + log.info("Just take " + item); + switch (item.getAction()) { + case ADD: + break; + case CHANGELOG: + break; + case CHECKOUT: + break; + case COMMIT: + break; + case DELETE: + break; + case DIFF: + break; + case OVERWRITE_AND_UPDATE: + break; + case REFRESH: + break; + case REVERT: + break; + case UPDATE: + break; + } + } + + +} Modified: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/handler/AbstractConfirmUIHandler.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/handler/AbstractConfirmUIHandler.java 2008-04-04 19:32:29 UTC (rev 334) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/handler/AbstractConfirmUIHandler.java 2008-04-04 19:32:54 UTC (rev 335) @@ -15,7 +15,7 @@ package org.codelutin.vcs.ui.handler; import org.codelutin.vcs.VCSAction; -import org.codelutin.vcs.VCSActionManager; +import org.codelutin.vcs.runner.VCSActionManager; import org.codelutin.vcs.VCSFileState; import org.codelutin.vcs.VCSHandler; import org.codelutin.vcs.ui.VCSUIConstants;
participants (1)
-
tchemit@users.labs.libre-entreprise.org