Commons Sandbox
  1. Commons Sandbox
  2. SANDBOX-249

Add a base Inmplementation for StageContext


    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Pipeline
    • Labels:



      • Licensed to the Apache Software Foundation (ASF) under one or more
      • contributor license agreements. See the NOTICE file distributed with
      • this work for additional information regarding copyright ownership.
      • The ASF licenses this file to You 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
      • 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 org.apache.commons.pipeline;

      import java.util.ArrayList;
      import java.util.Collection;
      import java.util.Collections;
      import java.util.EventObject;
      import java.util.HashMap;
      import java.util.List;
      import java.util.Map;


      • This class provide an instance inmplementation of StageContext and maybe
      • extended to provided additional functionality of included in other classes
      • wishing to in the StageContext Interface
      • @author sheldon
        public class BaseContext implements StageContext {

      // Map of DownstreamFeeder having the Stage as key
      private final Map<Stage, Feeder> feeders;

      // Map of pipeline branches where the keys are branch names.
      private final Map<String,Pipeline> branches;

      // The list of listeners registered with the pipeline.
      private final List<StageEventListener> listeners;

      // Global environment variables
      private Map<String,Object> env = Collections.synchronizedMap(new HashMap<String,Object>());

      public BaseContext()

      { this.feeders = new HashMap<Stage, Feeder>(); this.branches = new HashMap<String,Pipeline>(); this.listeners = Collections.synchronizedList(new ArrayList<StageEventListener>()); }

      public Feeder getBranchFeeder(String branch)

      { return branches.get(branch).getSourceFeeder(); }


      • Add a branch {@link Pipeline}

        to the Stage

      • @param key a string allowing the look-up of a branch
      • @param branch a Pipeline added to Stage
      • @return Pipeline The prior Pipeline corresponding to the key
        public Pipeline addBranch(String key, Pipeline branch) { return branches.put(key,branch); }

      public Feeder getDownstreamFeeder(Stage stage)

      { return feeders.get(stage)!= null?feeders.get(stage):Feeder.VOID; }

      public Feeder addDownstreamFeeder(Stage stage, Feeder feeder) throws IllegalArgumentException

      { if(stage != null) return feeders.put(stage, feeder); else throw new IllegalArgumentException("Attempted insert of null stage"); }

      public Object getEnv(String key)

      { return env.get(key); }


      • Sets a global environment variable for the stage.
      • @param key a string to look-up the an environment variable
      • @param value The Object to set for the variable
      • @return Object The prior object corresponding to the key
        public Object setEnv(String key, Object value) { return env.put(key, value); }

      public Collection<StageEventListener> getRegisteredListeners()

      { return listeners; }

      public void raise(final EventObject ev) {
      for (final StageEventListener listener : listeners) {
      new Thread() {
      public void run()

      { listener.notify(ev); }



      public void registerListener(StageEventListener listener)

      { listeners.add(listener); }



        Sheldon Robinson created issue -


          • Assignee:
            Sheldon Robinson
          • Votes:
            0 Vote for this issue
            0 Start watching this issue


            • Created:

              Time Tracking

              Original Estimate - 0.25h
              Remaining Estimate - 0.25h
              Time Spent - Not Specified
              Not Specified