Return-Path: X-Original-To: apmail-activemq-commits-archive@www.apache.org Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0A9AD789B for ; Thu, 14 Jul 2011 20:30:07 +0000 (UTC) Received: (qmail 85830 invoked by uid 500); 14 Jul 2011 20:30:06 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 85766 invoked by uid 500); 14 Jul 2011 20:30:06 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 85759 invoked by uid 99); 14 Jul 2011 20:30:06 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Jul 2011 20:30:06 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Jul 2011 20:30:03 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 697D523888CF for ; Thu, 14 Jul 2011 20:29:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1146885 - /activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/BaseService.scala Date: Thu, 14 Jul 2011 20:29:42 -0000 To: commits@activemq.apache.org From: chirino@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110714202942.697D523888CF@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: chirino Date: Thu Jul 14 20:29:41 2011 New Revision: 1146885 URL: http://svn.apache.org/viewvc?rev=1146885&view=rev Log: Simpler more robust callback handling for the BaseService class. Modified: activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/BaseService.scala Modified: activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/BaseService.scala URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/BaseService.scala?rev=1146885&r1=1146884&r2=1146885&view=diff ============================================================================== --- activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/BaseService.scala (original) +++ activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/BaseService.scala Thu Jul 14 20:29:41 2011 @@ -49,17 +49,11 @@ trait BaseService extends Service with D def is_failed= false } - trait CallbackSupport { - var callbacks:List[Runnable] = Nil - def << (r:Runnable) = if(r!=null) { callbacks ::= r } - def done = { callbacks.foreach(_.run); callbacks=Nil } - } - protected class CREATED extends State { override def is_created = true } - protected class STARTING extends State with CallbackSupport { override def is_starting = true } + protected class STARTING extends State { override def is_starting = true } protected class FAILED extends State { override def is_failed = true } protected class STARTED extends State { override def is_started = true } - protected class STOPPING extends State with CallbackSupport { override def is_stopping = true } + protected class STOPPING extends State { override def is_stopping = true } protected class STOPPED extends State { override def is_stopped = true } final def start() = start(null) @@ -78,14 +72,21 @@ trait BaseService extends Service with D final def start(on_completed:Runnable) = { def start_task:Runnable = ^{ + def done = { + pending_actions.foreach(dispatch_queue.execute _) + pending_actions.clear() + if( on_completed!=null ) { + on_completed.run + } + } + def do_start = { val state = new STARTING() - state << on_completed _service_state = state try { _start(^ { _service_state = new STARTED - state.done + done }) } catch { @@ -93,16 +94,10 @@ trait BaseService extends Service with D error(e, "Start failed due to %s", e) _serviceFailure = e _service_state = new FAILED - state.done - } - } - def done = { - pending_actions.foreach(dispatch_queue.execute _) - pending_actions.clear() - if( on_completed!=null ) { - on_completed.run + done } } + _service_state match { case state:CREATED => do_start @@ -125,8 +120,9 @@ trait BaseService extends Service with D final def stop(on_completed:Runnable) = { def stop_task:Runnable = ^{ def done = { - pending_actions.foreach(dispatch_queue.execute _) + val tmp = pending_actions.toArray pending_actions.clear + tmp.foreach(dispatch_queue.execute _) if( on_completed!=null ) { on_completed.run } @@ -134,12 +130,11 @@ trait BaseService extends Service with D _service_state match { case state:STARTED => val state = new STOPPING - state << on_completed _service_state = state try { _stop(^ { _service_state = new STOPPED - state.done + done }) } catch { @@ -147,7 +142,7 @@ trait BaseService extends Service with D error(e, "Stop failed due to: %s", e) _serviceFailure = e _service_state = new FAILED - state.done + done } case state:STOPPED => done