Code Search for Developers
 
 
  

ParallelHello.java from GridBlocks at Krugle


Show ParallelHello.java syntax highlighted

/*
 * Copyright (c) 2006
 * Helsinki Institute of Physics
 * see LICENSE file for details
 *
 * HelloWorldMulti.java
 */

import java.io.IOException;
import java.net.InetAddress;

import fi.hip.gb.mobile.AgentUndeployer;
import fi.hip.gb.mobile.MobileAgent;

/**
 * A simple example of how to create parallel applications. The target
 * server should have AOP enabled.
 * 
 * @author Juho Karppinen
 */
@MobileAgent (singleton=true,discoveryURL="http://opengrid.cern.ch:8080/gb-agent")
public class ParallelHello {
	public ParallelHello() {
	}

    /**
     * Creates n parallel HelloWorld threads.
     * 
     * @param param parameter for the hello world
     * @param multiply multiply hello messages n times
     * @return combined hello world message
     */
    public String getHello(final String param, int multiply) throws IOException {
        //System.out.println("Hello method '" + param + "' , '" + multiply + "'");
        final StringBuffer result = new StringBuffer();
        
        // start processes on the background
        Thread[] proc = new Thread[multiply];
        for (int i = 0; i < multiply; i++) {
            proc[i] = new Thread(new Runnable() {
                public void run() {
                    try {
                        result.append("\t" + new HelloWorld().getHello(param) + "\n");
                    } catch (IOException e) {
                        result.append("\t failed: " + e.getMessage() + "\n");
                    }
                }
            });
            proc[i].start();
        }
        
        // wait until everything is finished
        for (int i = 0; i < multiply; i++) {
            try {
                proc[i].join();
            } catch (InterruptedException e) {
                throw new IOException("InterruptedException " + e.getMessage());
            }
        }
        
        return "Hello world X on " + InetAddress.getLocalHost().getHostName()
                + " results to\n " + result;
    }
    
    @AgentUndeployer
    public void undeploy() {
    }
    
    public static void main(String[] args) throws Exception {
        ParallelHello hello = new ParallelHello();
        System.out.println("returned: " + hello.getHello("hi", 2));
        hello.undeploy();
    }
}



See more files for this project here

GridBlocks

GridBlocks builds a grid application framework via easy-to-use building blocks in distributed environment. The framework offers components for Grid security, distributed storage, computing, and Portlet web interfaces.

Project homepage: http://sourceforge.net/projects/gridblocks
Programming language(s): Java,JSP,XML
License: other

  chess/
    data/
      Piece.java
      Ply.java
      Square.java
    logic/
      Analyzer.java
      CheckMate.java
      GameState.java
      Generator.java
      Iterator.java
      Validator.java
    ui/
      Board.java
      CheckGUI.java
  mandelbrot/
    fractal/
      MandelBrotSliceGenerator.java
      MandelbrotGenerator.java
    math/
      ComplexNumber.java
      ComplexRectangle.java
    ui/
      ImagePanel.java
      LogarithmicPalette.java
      MandelbrotSurfer.java
  org/
    grafki/
    nordugrid/
      job/
        gridftp/
          ARCGridFTPJob.java
          ARCGridFTPJobException.java
          ARCGridFTPJobInterface.java
          Makefile
          NGClient.java
          Test.java
          test.txt
        mds/
          ARCMDSDiscovery.java
          Makefile
          Test.java
          mdsdiscovery.h
          mdsquery.h
  unosat/
  FileFetcher.java
  FileObserver.java
  HelloWorld.java
  ImageGallery.java
  ImageObserver.java
  NorduGrid.java
  ParallelHello.java
  Shell.java
  Sleeper.java
  Stateful.java
  Webster.java