| ¥¨¡¼¥¸¥§¥ó¥È̾ | ¥Õ¥¡¥¤¥ë̾ | ÀâÌÀ |
|---|---|---|
| ClipSender | ClipSender.dash | ¥ª¥Ö¥¸¥§¥¯¥È¤òÅϤ¹¥¨¡¼¥¸¥§¥ó¥È |
| ClipSender.class | ¥Ù¡¼¥¹¥×¥í¥»¥¹ | |
| ClipReceiver | ClipReceiver.dash | ¥ª¥Ö¥¸¥§¥¯¥È¤ò¤â¤é¤¦¥¨¡¼¥¸¥§¥ó¥È |
| ClipReceiver.class | ¥Ù¡¼¥¹¥×¥í¥»¥¹ | |
| ¤Ê¤· | MyClass.class | ¼õ¤±ÅϤµ¤ì¤ë¼«ºî¥ª¥Ö¥¸¥§¥¯¥È |
(2.1)ClipSender
(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
(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
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 }
|