LOGIN   :::   RECOVER PASS   :::   GET ACCOUNT    
Browse
  • Projects
  • Code (CVS)
  • Forums
  • News
  • Articles
  • Polls
  •  
    OpenCores
  • FAQ
  • CVS HowTo
  • Mission
  • Media
  • Tools
  • Advertise
  • Mirrors
  • Logos
  • Contact us
  • Find Resources
  • Job Opportunity
  •  
    Tools
  • Search
      
  • Download Cores (CVSGet)
  •  
    More
  • Wishbone
  • Perlilog
  • EDA tools
  • OpenTech CD
  •  
    Navigation: All forums > Cvs-checkins > Message List > Message Post

    Message

    Reply | Reply all
    Date Prev | Date Next | Thread Prev | Thread Next Date Index | Thread Index

    From: cvs at opencores.org<cvs@o...>
    Date: Tue Jul 24 15:03:28 CEST 2007
    Subject: [cvs-checkins] MODIFIED: jop ...
    Top
    Date: 00/07/07 24:15:03

    Added: jop/java/tools/src/wcet/framework/util
    ClassLoaderSingleton.java ComponentRunner.java
    Log:



    Revision Changes Path
    1.1 jop/java/tools/src/wcet/framework/util/ClassLoaderSingleton.java

    http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/wcet/framework/util/ClassLoaderSingleton.java?rev=1.1&content-type=text/x-cvsweb-markup

    Index: ClassLoaderSingleton.java
    ===================================================================
    /**
    *
    */
    package wcet.framework.util;

    import java.io.File;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLClassLoader;
    import java.util.StringTokenizer;

    /**
    * @author Elena Axamitova
    * @version 0.3 04.02.2007
    *
    * Provides the class loader instance for init of analyser components
    */
    public class ClassLoaderSingleton {
    static ClassLoader instance = null;

    private ClassLoaderSingleton() {

    }

    public static ClassLoader getInstance() {
    if(instance==null)
    instance = ClassLoader.getSystemClassLoader();
    return instance;
    }

    public static void addLibrary(String path) {
    if(instance==null)
    instance = ClassLoader.getSystemClassLoader();
    if (path != null) {
    StringTokenizer tokenizer = new StringTokenizer(path,
    File.pathSeparator);
    URL[] libraryURLs = new URL[tokenizer.countTokens()];
    for (int i = 0; tokenizer.hasMoreTokens(); i++) {
    try {
    String libraryURL = "file:///" + tokenizer.nextToken();
    libraryURLs[i] = new URL(libraryURL);
    } catch (MalformedURLException e) {
    // ignore
    }
    }
    instance = new URLClassLoader(libraryURLs, instance);
    }
    }
    }



    1.1 jop/java/tools/src/wcet/framework/util/ComponentRunner.java

    http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/wcet/framework/util/ComponentRunner.java?rev=1.1&content-type=text/x-cvsweb-markup

    Index: ComponentRunner.java
    ===================================================================
    /**
    *
    */
    package wcet.framework.util;

    import java.io.PrintStream;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Hashtable;
    import java.util.Iterator;
    import java.util.LinkedList;
    import java.util.List;
    import java.util.Queue;
    import java.util.Vector;
    import java.util.concurrent.ExecutionException;
    import java.util.concurrent.ExecutorService;
    import java.util.concurrent.Executors;
    import java.util.concurrent.Future;
    import java.util.concurrent.TimeUnit;

    import wcet.framework.exceptions.SurplusComponentException;
    import wcet.framework.exceptions.TaskExecutionException;
    import wcet.framework.interfaces.general.IAnalyserComponent;
    import wcet.framework.interfaces.util.IComponentRunner;

    /**
    * A simple implementation of the IComponentRunner interface.
    *
    * @author Elena Axamitova
    * @version 0.3 */ public final class ComponentRunner implements IComponentRunner { private PrintStream output; /** * Component storage */ private Hashtable<Integer, LinkedList<IAnalyserComponent>> components; /** * Creates a ComponentRunner object */ public ComponentRunner() { this.components = new Hashtable<Integer, LinkedList<IAnalyserComponent>>( 10); } /* (non-Javadoc) * @see wcet.framework.interfaces.util.IComponentRunner#setOutput(java.io.PrintStream) */ public void setOutput(PrintStream ps) { this.output = ps; } /* * (non-Javadoc) * * @see wcet.interfaces.util.IComponentRunner#registerComponent(wcet.interfaces.general.IAnalyserComponent) */ public void registerComponent(IAnalyserComponent component) throws SurplusComponentException { Integer order = Integer.valueOf(component.getOrder()); LinkedList<IAnalyserComponent> concurrentComponents = this.components .get(order); if (concurrentComponents == null) { concurrentComponents = new LinkedList<IAnalyserComponent>(); concurrentComponents.add(component); } else if (component.getOnlyOne() == true) { throw new SurplusComponentException( "There is a previously registred component of the same order and the new component of type " + component.getClass().getCanonicalName() + " does not allow concurrency."); } else { IAnalyserComponent present = concurrentComponents.getFirst(); if (present.getOnlyOne()) { throw new SurplusComponentException( "Previously registred component of type " + present.getClass().getCanonicalName() + " does not allow concurrency."); } else { concurrentComponents.add(component); } } this.components.put(order, concurrentComponents); } /* * (non-Javadoc) * * @see wcet.interfaces.util.IComponentRunner#removeComponent(wcet.interfaces.general.IAnalyserComponent) */ public boolean removeComponent(IAnalyserComponent component) { Integer order = Integer.valueOf(component.getOrder()); LinkedList<IAnalyserComponent> concurrentComponents = this.components .get(order); if (concurrentComponents != null) { return concurrentComponents.remove(component); } return false; } /* * (non-Javadoc) * * @see wcet.interfaces.util.IComponentRunner#startComponents() */ public void startComponents() throws TaskExecutionException { //component are executed, sorted by their order Vector<Integer> orderNr = new Vector<Integer>(this.components.keySet()); Collections.sort(orderNr); int firstOrderNr = orderNr.firstElement().intValue(); int lastOrderNr = orderNr.lastElement().intValue(); for (int i = firstOrderNr; i <= lastOrderNr; i++) { Integer currPriority = Integer.valueOf(i); if (components.containsKey(currPriority)) { //components of the same order are executed concurrently this.callComponents(currPriority); } } } /* * Executes all regisred components with the given priority one after * one * * @param priority - the priority of the components to be executed * @throws TaskExecutionException - when problems occur */ /* * private void executeComponents(Integer priority) throws * TaskExecutionException { Queue<IAnalyserComponent> sortedComponents = * components.get(priority); String messages = null; while * (!sortedComponents.isEmpty()) { try { messages = * sortedComponents.poll().call(); if (messages != null) { * System.out.println(messages); } } catch (Exception e) { throw new * TaskExecutionException(e); } } * } */ /** * Runs all regisred components with the given priority concurrently. * * @param priority - * the priority of the components to be executed * @throws TaskExecutionException - * when problems occur */ private void callComponents(Integer priority) throws TaskExecutionException { Queue<IAnalyserComponent> concurrentComponents = components .get(priority); ExecutorService myExecService = Executors.newFixedThreadPool(10); List<Future<String>> results = new ArrayList<Future<String>>(); while (!concurrentComponents.isEmpty()) { results.add(myExecService.submit(concurrentComponents.poll())); } try { myExecService.shutdown(); myExecService.awaitTermination(3000, TimeUnit.SECONDS); for (Iterator<Future<String>> iterator = results.iterator(); iterator .hasNext();) { Future<String> currResult = iterator.next(); try { String message = currResult.get(); if ((this.output != null) && (message != null)) this.output.println(message); } catch (ExecutionException e) { throw new TaskExecutionException(e); } } } catch (InterruptedException e) { throw new TaskExecutionException(e); } } }

     
    Copyright (c) 1999 OPENCORES.ORG. All rights reserved.