parentbase.java

来自「ajax patterns 这是关于ajax设计模式方面的原代码」· Java 代码 · 共 65 行

JAVA
65
字号
/*
    Copyright 2006 Christian Gross http://www.devspace.com
    From the book Ajax Patterns and Best Practices

   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 devspace.ajax.restMVC;
import java.util.*;

public abstract class ParentBase implements Parent {
    private List _commands = new LinkedList();
    
    public void addCommand( Command cmd) {
        _commands.add( cmd);
    }
    public Iterator getCommands() {
        return _commands.iterator();
    }
    public void clearAllCommands() {
        _commands.clear();
    }
    
    protected List _runningThreads = new LinkedList();
    public abstract<resultType> void addResult(resultType result);
    
    public void processRequest( Request request) {
        Iterator iter = _commands.iterator();
        _runningThreads.clear();
        while( iter.hasNext()) {
            Command cmd = (Command)iter.next();
            cmd.setRequest( request);
            cmd.assignParent( this);
            Thread thrd = new Thread((Runnable)cmd);
            _runningThreads.add( thrd);
            thrd.start();
        }
    }
    public void processRequest( String impl, Request request) {
        Iterator iter = _commands.iterator();
        _runningThreads.clear();
        while( iter.hasNext()) {
            Command cmd = (Command)iter.next();
            if( cmd.getIdentifier().compareTo( impl) == 0) {
                cmd.setRequest( request);
                cmd.assignParent( this);
                Thread thrd = new Thread( (Runnable)cmd);
                _runningThreads.add( thrd);
                thrd.start();
                break;
            }
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?