⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parpattern.java

📁 移动Agent编程工具Naplet
💻 JAVA
字号:

/*
 * @<#>ParPattern.java version 0.0.1, 1/1/2000
 *
 * THIS PROGRAM IS FREE SOFTWARE; YOU CAN DISTRIBUTE IT AND/OR
 * MODIFY IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE 
 * AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION.
 *
 * THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
 * BUT WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE 
 * GNU GENERAL PUBLIC LICENSE FOR MORE DETAILS.
 *
 * Copyright (c) 2000 Wayne State University. All Rights Reserved.
 */
package naplet.itinerary;

import java.util.*;
import naplet.*;
import naplet.message.AddressBook;

/**
 * The <code>ParPattern</code> class implements a primitive of 
 * parallel itinerary. Naplets are cloned and dispatched simultanesouly
 * to naplet servers.
 *
 * @version 0.0.1, 1/1/2000
 * @author C. Xu
 */

public class ParPattern extends CompositePattern {

	public ParPattern(String[] hosts)
			throws InvalidItineraryException {
		super(null, hosts, null );
	}

	public ParPattern(String[] hosts, Operable act)
			throws InvalidItineraryException {
		super(null, hosts, act);
	}

	public ParPattern(Checkable guard, String[] hosts )
			throws InvalidItineraryException {
		super(guard, hosts, null);
	}

	public ParPattern(Checkable guard, String[] hosts, Operable act)
			throws InvalidItineraryException {
		super(guard, hosts, act);
	}

	public ParPattern(ItineraryPattern[] itin) {
		super(null, itin, null );
	}

	public ParPattern(ItineraryPattern[] itin, Operable act) {
		super(null, itin, act );
	}

	public ParPattern(Checkable guard, ItineraryPattern[] itin ) {
		super(guard, itin, null );
	}

	public ParPattern(Checkable guard, ItineraryPattern[] itin, Operable act) {
		super(guard, itin, act );
	}

	/**
	 * Clone naplets and dispatch them to different routes
	 */
	public void go( Naplet nap )
			throws java.rmi.RemoteException, UnableDispatchException {
		
		// At the beinning of a ParPattern, clone naplets and include
		// the newly created naplets in their communicators. 

		if (iter.hasNext() ) {
			
			if ( guard==null || guard.check(nap) ) { 
				// Conditional visit
				int size = itinerarySize();
				Naplet[] newNaps = new Naplet[size];
				NapletID[] nids = new NapletID[size];
				URN[] servers = new URN[size];
	
				for (int i=0; i<size; i++) {
					newNaps[i] = (Naplet) nap.clone();
					nids[i] = newNaps[i].getNapletID();
				}
	
				for (int i=0; iter.hasNext(); i++ ){
					ItineraryPattern itin = iter.next();
					servers[i] = itin.first();
				}

				for (int i=0; i<size; i++) {
					AddressBook aBook = newNaps[i].getAddressBook();
					aBook.addAll( nids, servers );
	
					// Update owner of their address books
					try {
						aBook.setOwner( nids[i] );
					} catch (InvalidNapletException ine) {
						throw new NapletInternalError(ine.getMessage());
					}
				}	

				nap.getAddressBook().addAll( nids, servers );
			
				iter.reset();
				for (int i = 0; iter.hasNext(); i++ ) { 
					ItineraryPattern next = iter.next();
					newNaps[i].getItinerary().pushRoute( 
							nap.getItinerary().getRoute() );
					newNaps[i].getItinerary().setRoute(next);
					next.go( newNaps[i] );
				}	

				if (action!=null) {
					action.operate( nap );
				}
			} else { 		// skip Par sequence	
				ItineraryPattern itin = nap.getItinerary().popRoute();
				if (itin == null)
					System.out.println("End of Itinerary");	
				else {
					nap.getItinerary().setRoute( itin ); 
					itin.go( nap );
				} 
			}
		} else {	
			
			// Reset iterator for future possible itinerary loop
			iter.reset();

			ItineraryPattern itin = nap.getItinerary().popRoute();
			if (itin == null)
				System.out.println("End of Itinerary");	
			else {
				nap.getItinerary().setRoute( itin ); 
				itin.go( nap );
			} 
		}	
	}

}
		

	


⌨️ 快捷键说明

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