Details
-
Improvement
-
Status: Open
-
Major
-
Resolution: Unresolved
-
None
-
None
-
None
Description
/*
- 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
* - 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 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>()); } @Override
public Feeder getBranchFeeder(String branch)
/**
- 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); }
@Override
public Feeder getDownstreamFeeder(Stage stage)
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"); } @Override
public Object getEnv(String 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); }
@Override
public Collection<StageEventListener> getRegisteredListeners()
@Override
public void raise(final EventObject ev) {
for (final StageEventListener listener : listeners) {
new Thread() {
public void run()
}.start();
}
}
@Override
public void registerListener(StageEventListener listener)
}