ÎãÂê04c ¥Ù¡¼¥¹¥×¥í¥»¥¹´Ö¤Î¥ª¥Ö¥¸¥§¥¯¥È¼õ¤±ÅϤ·

(1)³µÍ×

¥¨¡¼¥¸¥§¥ó¥È¤¬»ý¤Ä¥Ù¡¼¥¹¥×¥í¥»¥¹´Ö¤Ç¥ª¥Ö¥¸¥§¥¯¥È¤ò¼õ¤±ÅϤ¹ÊýË¡¤ò¼¨¤¹¡£
(Ãí°Õ¡§¥Í¡¼¥à¥µ¡¼¥ÐNameServer.jar¤Îµ¯Æ°¤¬É¬Íס£)

(2)¥¨¡¼¥¸¥§¥ó¥È

¥¨¡¼¥¸¥§¥ó¥È̾¥Õ¥¡¥¤¥ë̾ÀâÌÀ
ClipSenderClipSender.dash¥ª¥Ö¥¸¥§¥¯¥È¤òÅϤ¹¥¨¡¼¥¸¥§¥ó¥È
ClipSender.class
¥Ù¡¼¥¹¥×¥í¥»¥¹
ClipReceiverClipReceiver.dash¥ª¥Ö¥¸¥§¥¯¥È¤ò¤â¤é¤¦¥¨¡¼¥¸¥§¥ó¥È
ClipReceiver.class
¥Ù¡¼¥¹¥×¥í¥»¥¹
¤Ê¤·MyClass.class¼õ¤±ÅϤµ¤ì¤ë¼«ºî¥ª¥Ö¥¸¥§¥¯¥È

(2.1)ClipSender

¡üÃμ±µ­½Ò¥Õ¥¡¥¤¥ë (ClipSender.dash)
(agent ClipSender
 
 (property
  (create :author "taka")
 )
 
 (initial_facts
 )
 
 (knowledge
    (rule startup
      (Msg :performative __INIT_I)
      (Status :name ?name)
      -->
      (inspect nonstop)
      (loadBP baseProcess.dashSample.ClipSender)  // BPÆɤ߹þ¤ß
      (startBP)                         // run()¸Æ¤Ó½Ð¤·
      (bind ?t (current-time))
      (make (key :name ?name :time ?t))
    )
    
    //¥­¡¼¤òÍѤ¤¤¿¼«ºî¥ª¥Ö¥¸¥§¥¯¥È¤Î³ÊǼ
    (rule putmyclass
      (key :name ?name :time ?t) = ?arg
      -->
      (bind ?key (toString ?arg))
      //¥­¡¼¤òÍѤ¤¤Æ¡¢DVMÆ⥯¥ê¥Ã¥×¥Ü¡¼¥É¤Ë
      //¼«ºî¥ª¥Ö¥¸¥§¥¯¥È¤ò³ÊǼ
      (control putMyClass(?key))
    )

    //¥­¡¼Í×µá¤ò¼õ¤±¼è¤ê¡¢¥­¡¼¤òÁ÷¤ë
    (rule receive-keyRequest
      (Msg :performative keyRequest :from ?sender ) = ?msg
      (key :name ?name :time ?t) = ?arg
      -->
      (bind ?key (toString ?arg))
      (send :performative sendKey :to ?sender :content (?key))
      (remove ?msg)
    )
  )
)

¡ü¥Ù¡¼¥¹¥×¥í¥»¥¹ (ClipSender.java)
package baseProcess.dashSample;

import dash.*;

/**
 * ClipSender
 */
public class ClipSender implements DashBP {

	private DashAgent agent;

	/** ¥³¥ó¥¹¥È¥é¥¯¥¿¡£¥¢¥¯¥·¥ç¥ó(loadBP)¼Â¹Ô»þ¤Ë¸Æ¤Ð¤ì¤ë¡£ */
	public ClipSender() {
	}

	/** ¥¢¥¯¥·¥ç¥ó(loadBP)¼Â¹Ô»þ¤Ë¸Æ¤Ð¤ì¤ë¡£*/
	public void setAgent(DashAgent agent) {
		this.agent = agent;
	}

	/** ¥¢¥¯¥·¥ç¥ó(startBP)¼Â¹Ô»þ¤Ë¸Æ¤Ð¤ì¤ë */
	public void run() {
	}

	/** ¥¨¡¼¥¸¥§¥ó¥È¤Î½ªÎ»»þ¤Ë¸Æ¤Ð¤ì¤ë */
	public void finalizeBP() {
	}

	//¼«ºî¥ª¥Ö¥¸¥§¥¯¥È¤Î³ÊǼ
	public void putMyClass(Object[] str) {
		String key = (String) str[0];
		MyClass mc = new MyClass();
		//DVM(Dash Virtual Machine)Æâ¤Î¥¯¥ê¥Ã¥×¥Ü¡¼¥É¤Ë
		//¼«ºî¥ª¥Ö¥¸¥§¥¯¥È¤ò³ÊǼ
		agent.cm.putSerialized(key, mc);
	}
}

(2.2)ClipReceiver

¡üÃμ±µ­½Ò¥Õ¥¡¥¤¥ë (ClipReceiver.dash)
(agent ClipReceiver
 
 (property
  (create :author "taka")
 )
 
 (initial_facts
 )
 
 (knowledge
    (rule startup
      (Msg :performative __INIT_I)
      (Status :name ?name)
      -->
      (inspect nonstop)
      (loadBP baseProcess.dashSample.ClipReceiver)  // BPÆɤ߹þ¤ß
      (startBP)                          // run()¸Æ¤Ó½Ð¤·
      (control startup ())
    )

    // ¥Ù¡¼¥¹¥×¥í¥»¥¹¤«¤é¤Î¥¤¥Ù¥ó¥È¤ò¼õ¤±¼è¤ê¡¢
    // ClipSender¤Ë¥­¡¼¤òÍ׵᤹¤ë
    (rule event-handling
      (Msg :performative __Event :content (?string)) = ?msg
      -->
      (bind ?agents (lookup :rname ClipSender))
      (bind ?agent (shift ?agents))
      (send :performative keyRequest :to ?agent:name :content ())
      (remove ?msg)
     )
    
    // ClipSender¤«¤é¡¢¥­¡¼¤ò¼õ¤±¼è¤ë
    (rule receive-sendKey
     (Msg :performative sendKey :from ?sender :content (?key)) = ?msg
     -->
     //¥­¡¼¤òÍѤ¤¤Æ¡¢DVMÆâ¤Î¥¯¥ê¥Ã¥×¥Ü¡¼¥É¤«¤é¼«ºî¥ª¥Ö¥¸¥§¥¯¥È¤ò¼è¤ê½Ð¤¹
     (control getMyClass (?key))
     (remove ?msg)
    )
  )
)

¡ü¥Ù¡¼¥¹¥×¥í¥»¥¹ (ClipReceiver.java)
package baseProcess.dashSample;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import dash.*;
import java.io.*;

public class ClipReceiver extends JFrame implements DashBP, ActionListener {

	private DashAgent agent;

	JTextArea textarea;
	JButton startbutton;
	JButton stopbutton;

	/** ¥³¥ó¥¹¥È¥é¥¯¥¿¡£¥¢¥¯¥·¥ç¥ó(loadBP)¼Â¹Ô»þ¤Ë¸Æ¤Ð¤ì¤ë¡£ */
	public ClipReceiver() {
		super("ClipReceiver");
	}

	/** ¥¢¥¯¥·¥ç¥ó(loadBP)¼Â¹Ô»þ¤Ë¸Æ¤Ð¤ì¤ë¡£*/
	public void setAgent(DashAgent agent) {
		this.agent = agent;
	}

	/** ¥¢¥¯¥·¥ç¥ó(startBP)¼Â¹Ô»þ¤Ë¸Æ¤Ð¤ì¤ë
	 *
	 * */
	public void run() {
	}

	//¥­¡¼¤òÍѤ¤¤Æ¼«ºî¥ª¥Ö¥¸¥§¥¯¥È¤ò¼è¤ê½Ð¤¹
	public void getMyClass(Object[] str) {
		String key = (String) str[0];
		try {
			//DVM(Dash Virtual Machine)Æâ¤Î¥¯¥ê¥Ã¥×¥Ü¡¼¥É¤«¤é
			//¼«ºî¥ª¥Ö¥¸¥§¥¯¥È¤ò¼è¤ê½Ð¤¹
			ObjectInputStream ois =
				(ObjectInputStream) agent.cm.getObjectInputStream(key);
			MyClass mc = (MyClass) ois.readObject();
			agent.cm.remove(key);
			//¼èÆÀ¸å¤Î½èÍý
			textarea.append(mc.printDate());
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	/** ¥¨¡¼¥¸¥§¥ó¥È¤Î½ªÎ»»þ¤Ë¸Æ¤Ð¤ì¤ë */
	public void finalizeBP() {
		dispose();
	}

	/** start¥Ü¥¿¥ó¤ò²¡¤·¡¢¥¨¡¼¥¸¥§¥ó¥È¤Ë¥¤¥Ù¥ó¥È¤ò¾å¤²¤ë */
	public void actionPerformed(ActionEvent ae) {
		if (agent != null) {
			if (((JButton) ae.getSource()).getText().equals("Start")) {
				agent.raiseEvent("start");
			} else if (((JButton) ae.getSource()).getText().equals("Finish")) {
				dispose();
			}
		}
	}

	/** ¥ë¡¼¥ëstartupÆâ¤Ç¸Æ¤Ó½Ð¤µ¤ì¤ë */
	public void startup() {
		setup();
		// ¤È¤­¤É¤­null¤Ê¤³¤È¤¬¤¢¤ë
		while (textarea == null)
			try {
				Thread.sleep(500);
			} catch (InterruptedException e) {
			}
		textarea.append("µ¯Æ°\n");
	}

	/** ¥¦¥£¥ó¥É¥¦¤òºî¤ë */
	private void setup() {
		textarea = new JTextArea(6, 20);
		JScrollPane sc = new JScrollPane(textarea);
		sc.setBorder(new TitledBorder("Input"));

		startbutton = new JButton("Start");
		startbutton.addActionListener(this);

		stopbutton = new JButton("Finish");
		stopbutton.addActionListener(this);

		JPanel panel = new JPanel();
		panel.add(startbutton);
		panel.add(stopbutton);

		GridLayout layout = new GridLayout(1, 2);
		panel.setLayout(layout);

		getContentPane().add(sc, BorderLayout.CENTER);
		getContentPane().add(panel, BorderLayout.SOUTH);

		pack();
		setVisible(true);
	}
}

(2.3)MyClass

¡ü¥Ù¡¼¥¹¥×¥í¥»¥¹ (MyClass.java)
     1  package baseProcess.dashSample;
     2 
     3  import java.io.Serializable;
     4  import java.util.Calendar;
     5
     6  /**
     7   * º£Æü¤Îǯ·îÆü¤òɽ¼¨¤¹¤ë¥¯¥é¥¹
     8   */
     9  public class MyClass implements Serializable {
    10    int year;
    11    int month;
    12    int date;
    13
    14    public MyClass() {
    15      Calendar c = Calendar.getInstance();
    16      year = c.get(Calendar.YEAR);
    17      month = c.get(Calendar.MONTH) + 1;
    18      date = c.get(Calendar.DATE);
    19    }
    20
    21    public String printDate() {
    22      return year + "ǯ" + month + "·î" + date + "Æü";
    23    }
    24  }

(3)½èÍý¤Îή¤ì

­¡ClipSender¥¨¡¼¥¸¥§¥ó¥È¡¢ClipReceiver¥¨¡¼¥¸¥§¥ó¥È¤òµ¯Æ°¤¹¤ë

­¢ClipSender¥¨¡¼¥¸¥§¥ó¥È¤Ï¡¢¥­¡¼¤È¤Ê¤ë¥Õ¥¡¥¯¥È¤òÀ¸À®¤·¡¢¤½¤Î¥­¡¼¤òÍѤ¤¤ÆMyClass¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤òDVMÆâ¤Î¥¯¥ê¥Ã¥×¥Ü¡¼¥É¤Ë¥·¥ê¥¢¥é¥¤¥º¤·¤Æ³ÊǼ¤¹¤ë¡Ê agent.cm.putSerialized(key, myclass) ¡Ë


­£ClipReceiver¥¨¡¼¥¸¥§¥ó¥È¤Ï¡¢¥Ù¡¼¥¹¥×¥í¥»¥¹¤«¤é¼«ºî¥ª¥Ö¥¸¥§¥¯¥È¼èÆÀ³«»Ï¤Î¥¤¥Ù¥ó¥È¤ò¼õ¤±¼è¤ë¤È¡¢ClipSender¥¨¡¼¥¸¥§¥ó¥È¤ËÂФ·¥­¡¼Í×µá¥á¥Ã¥»¡¼¥¸¤òÅꤲ¡¢¥­¡¼¤ò¤â¤é¤¦

­¤ClipReceiver¥¨¡¼¥¸¥§¥ó¥È¤Ï¡¢¥­¡¼¤òÍѤ¤¤ÆDVMÆâ¤Î¥¯¥ê¥Ã¥×¥Ü¡¼¥É¤«¤éMyClass¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤ò¼èÆÀ¡Ê ObjectInputStream ois = (ObjectInputStream) agent.cm.getObjectInputStream(key); MyClass mc = (MyClass) ois.readObject() ¡Ë¤·¡¢¥á¥½¥Ã¥É¤ò¼Â¹Ô¤¹¤ë


[¥á¥â]
¡¦¼«ºî¥ª¥Ö¥¸¥§¥¯¥È¤Î¼õ¤±ÅϤ·¤Ï¥ª¥Ö¥¸¥§¥¯¥È¤Î¥³¥Ô¡¼¤¬ÅϤµ¤ì¤ë¤Î¤Ç¡¢¥ª¥Ö¥¸¥§¥¯¥È¤Î¶¦Í­¤Ë¤ÏÍøÍѤǤ­¤Ê¤¤¡£
¡¦¼«ºî¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤Ï¤Ê¤¯¡¢É¸½àJDK¥é¥¤¥Ö¥é¥êÆâ¤Î¥ª¥Ö¥¸¥§¥¯¥Èobj1¤Ï¡¢¶¦Í­¤È¤¤¤¦·Á¤Ç¼õ¤±ÅϤ·¤ò¹Ô¤¦¡£
³ÊǼ»þ¤Ï agent.cm.put(key, obj1);
¼èÆÀ»þ¤Ï Object1 obj1 = (Object1)agent.cm.get(key);
obj1¤Ï¥Ù¡¼¥¹¥×¥í¥»¥¹´Ö¤Ç¶¦Í­¤µ¤ì¤ë¡£