Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2604 - in development/main/test/components/acme-config: . src/main/net/dpml/test/acme/state

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell AT dpml.net
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r2604 - in development/main/test/components/acme-config: . src/main/net/dpml/test/acme/state
  • Date: Thu, 19 May 2005 00:11:14 +0000

Author: mcconnell AT dpml.net
Date: Thu May 19 00:11:11 2005
New Revision: 2604

Added:

development/main/test/components/acme-config/src/main/net/dpml/test/acme/state/

development/main/test/components/acme-config/src/main/net/dpml/test/acme/state/ManagedComponent.java

development/main/test/components/acme-config/src/main/net/dpml/test/acme/state/ManagingContainer.java
Modified:
development/main/test/components/acme-config/build.xml
Log:
add state managed components

Modified: development/main/test/components/acme-config/build.xml
==============================================================================
--- development/main/test/components/acme-config/build.xml (original)
+++ development/main/test/components/acme-config/build.xml Thu May 19
00:11:11 2005
@@ -7,7 +7,12 @@
<transit:import uri="artifact:template:dpml/magic/standard"/>

<target name="build" depends="standard.build">
-
+ <types xmlns="plugin:dpml/composition/dpml-composition-builder">
+ <type class="net.dpml.test.acme.config.ConfigurableComponent"
threadsafe="true"/>
+ <type class="net.dpml.test.acme.config.ConfigurableContainer"
threadsafe="true"/>
+ <type class="net.dpml.test.acme.state.ManagedComponent"
threadsafe="true"/>
+ <type class="net.dpml.test.acme.state.ManagingContainer"
threadsafe="true"/>
+ </types>
</target>

</project>

Added:
development/main/test/components/acme-config/src/main/net/dpml/test/acme/state/ManagedComponent.java
==============================================================================
--- (empty file)
+++
development/main/test/components/acme-config/src/main/net/dpml/test/acme/state/ManagedComponent.java
Thu May 19 00:11:11 2005
@@ -0,0 +1,224 @@
+/*
+ * Copyright 2005 Stephen J. McConnell.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.test.acme.state;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.logging.Logger;
+
+import net.dpml.parts.state.State;
+import net.dpml.parts.state.StateEvent;
+import net.dpml.parts.state.StateListener;
+
+/**
+ * Experimental component dealing with state management.
+ *
+ * @author <a href="mailto:info AT dpml.net";>The Digital Product Meta
Library</a>
+ */
+public class ManagedComponent implements StateListener
+{
+ // ------------------------------------------------------------------
+ // state
+ // ------------------------------------------------------------------
+
+ private final Logger m_logger;
+
+ // ------------------------------------------------------------------
+ // constructor
+ // ------------------------------------------------------------------
+
+ /**
+ * Creation of a component that describes an activity model.
+ *
+ * @param logger the logging channel assigned by the container
+ */
+ public ManagedComponent( final Logger logger, Context context )
+ {
+ m_logger = logger;
+ context.addStateListener( this );
+ }
+
+ /**
+ * Notify the listener of a state change. The supplied event
+ * contains the originating state and the state that is about to
+ * be committed.
+ *
+ * @param event the state change event
+ */
+ public void stateChanged( final StateEvent event )
+ {
+ State source = event.getFromState();
+ State destination = event.getToState();
+ final String message =
+ "transitioning from '"
+ + source.getName()
+ + "' to '"
+ + destination.getName()
+ + "'";
+ m_logger.info( message );
+ }
+
+ // ------------------------------------------------------------------
+ // concerns
+ // ------------------------------------------------------------------
+
+ public interface Context
+ {
+ void addStateListener( StateListener listener );
+ }
+
+ // ------------------------------------------------------------------
+ // implementation
+ // ------------------------------------------------------------------
+
+ private Logger getLogger()
+ {
+ return m_logger;
+ }
+
+ //
+ // The following methods are invoked by the state manager based on
+ // uris assigned to transitions. The state manager locates the method
+ // from the uri and invokes the operation after constructing arguments
+ // from the possible set of Logger, Object (component impl), State
(initial),
+ // and State (target). If the method requires the target state it must
+ // delcare both current and target state in the method parameters.
+ //
+
+ public void terminate( State state )
+ {
+ String name = state.getName();
+ getLogger().info( "handling termination within " + name );
+ }
+
+ public void start( State starting )
+ {
+ String from = starting.getName();
+ getLogger().info( "starting from within " + from );
+ }
+
+ public void stop()
+ {
+ getLogger().info( "stopping the component" );
+ }
+
+ //
+ // The following method is an example of a method invoked
+ // via an operation declaration. Operations do not trigger state
+ // change - instead they are gaurded methods that become visible
+ // to a controlling application when the state to which the operation
+ // is assigned becomes visible in the active state chain.
+ //
+
+ public void audit( State state )
+ {
+ StringBuffer buffer = new StringBuffer( "Audit Report" );
+ buffer.append( "\n-------------------------------------------------"
);
+ buffer.append( "\nState Model:" );
+ buffer.append( "\nCurrent State: " + state.getName() );
+ buffer.append( "\n-------------------------------------------------"
);
+ buffer.append( STATE_GRAPH.list() );
+ buffer.append( "\n-------------------------------------------------"
);
+ buffer.append( "\nClass Loader Stack" );
+ buffer.append( "\n-------------------------------------------------"
);
+ buffer.append( "\n" + getClass().getClassLoader().toString() );
+ buffer.append( "\n-------------------------------------------------"
);
+ getLogger().info( buffer.toString() );
+ }
+
+ // ------------------------------------------------------------------
+ // static utilities
+ // ------------------------------------------------------------------
+
+ public static final State STATE_GRAPH = new State();
+
+ static
+ {
+ //
+ // construct a state graph
+ //
+
+ State root = STATE_GRAPH;
+ State initialized = root.addState( "initialized" );
+ State available = root.addState( "available" );
+ State started = available.addState( "started" );
+ State stopped = available.addState( "stopped" );
+ State terminated = root.addTerminalState( "terminated" );
+
+ //
+ // create the handler declarations
+ //
+
+ try
+ {
+ //
+ // add system transitions dealing with initilization and
+ // termination - each transition is added to a particular
+ // state and is qualified with the uri of the handler to
+ // use, and the transitions target state
+ //
+
+ root.setInitialization( initialized );
+ root.setTerminator( new URI( "method:null" ), terminated );
+ started.setTerminator( new URI( "method:stop" ), stopped );
+
+ //
+ // add user (application) transitions
+ //
+
+ initialized.addTransition( "start", new URI( "method:start" ),
started );
+ started.addTransition( "stop", new URI( "method:stop" ), stopped
);
+ stopped.addTransition( "start", new URI( "method:start" ),
started );
+
+ //
+ // add an operations that is only accessible in the active state
chain
+ // when the component is in the started state
+ //
+
+ started.addOperation( "audit", new URI( "method:audit" ) );
+
+ }
+ catch( URISyntaxException e )
+ {
+ // will not happen
+ }
+ }
+
+ //
+ // The following class is an example of a transition handler. Instances
+ // of this class may be registered with the state manager and referenced
in
+ // transitiond via the urn "handler:[key]".
+ //
+
+ private static final Handler GENERIC_HANDLER = new Handler();
+
+ public static class Handler
+ {
+ public void handle( ManagedComponent instance, State state, State
target, Logger logger )
+ {
+ final String message =
+ "handling transition from ["
+ + state.getName()
+ + "] to ["
+ + target.getName()
+ + "]";
+ logger.info( message );
+ }
+ }
+}

Added:
development/main/test/components/acme-config/src/main/net/dpml/test/acme/state/ManagingContainer.java
==============================================================================
--- (empty file)
+++
development/main/test/components/acme-config/src/main/net/dpml/test/acme/state/ManagingContainer.java
Thu May 19 00:11:11 2005
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2005 Stephen J. McConnell.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.test.acme.state;
+
+import java.net.URI;
+import java.util.logging.Logger;
+
+import net.dpml.parts.control.Manager;
+import net.dpml.parts.model.Component;
+import net.dpml.parts.state.State;
+
+import net.dpml.activity.Startable;
+
+/**
+ * Demonstration of a component that manages the state of a contained part.
+ *
+ * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
+ */
+public class ManagingContainer implements Startable
+{
+ //------------------------------------------------------------------
+ // state
+ //------------------------------------------------------------------
+
+ private final Logger m_logger;
+ private final Parts m_parts;
+
+ //------------------------------------------------------------------
+ // constructor
+ //------------------------------------------------------------------
+
+ /**
+ * Creation of a composite component. This implementation demonstrates
+ * access to parts within itself and invocation of service and non-service
+ * operations on its parts.
+ *
+ * @param logger the logging channel asign by the container
+ */
+ public ManagingContainer( final Logger logger, Parts parts )
+ {
+ m_logger = logger;
+ m_parts = parts;
+ }
+
+ //------------------------------------------------------------------
+ // implementation
+ //------------------------------------------------------------------
+
+ public void start() throws Exception
+ {
+ Parts parts = getParts();
+ Component component = parts.getTestComponent();
+ component.initialize();
+ component.resolve();
+ component.apply( "start" );
+ component.execute( "audit" );
+ }
+
+ public void stop() throws Exception
+ {
+ Parts parts = getParts();
+ Component component = parts.getTestComponent();
+ component.terminate();
+ }
+
+ private Logger getLogger()
+ {
+ return m_logger;
+ }
+
+ private Parts getParts()
+ {
+ return m_parts;
+ }
+
+ //------------------------------------------------------------------
+ // concerns
+ //------------------------------------------------------------------
+
+ public interface Parts
+ {
+ Component getTestComponent();
+ }
+}



  • svn commit: r2604 - in development/main/test/components/acme-config: . src/main/net/dpml/test/acme/state, mcconnell, 05/18/2005

Archive powered by MHonArc 2.6.24.

Top of Page