The Praya Object Model
2001 July 31
$Date: 2001/09/11 06:19:20 $ $Revision: 1.8 $
Abstract
This document serves as an introduction to the praya object model. It is
currently woefully incomplete.
The Protocol
A Protocol
represents a single underlying client mechanism. For example, there are
separate Protocols subclasses for Yahoo
Pager, IRC,
Gale,
and Battle.net.
A given protocol instance will often be associated with one connection to a
messaging server. All subclasses of Protocol must have a no-argument
constructor.
The Message
Messages
are produced by Protocols. They represent messages received by the protocol.
The Recipient
The Recipient
represents a possible target to which you can send messages.
Example: Yahoo Pager
Here example, using the Yahoo client, of praya in use.
import wtanaka.praya.*;
import wtanaka.praya.obj.*;
import wtanaka.praya.yahoo.*;
import java.io.*;
import java.util.*;
public class YahooExample
{
public static void main (String[] args) throws IOException,
InterruptedException, NotSentException, IllegalCommandException
{
// Construct a new Protocol instance.
Protocol proto = new YahooClient();
// Add a listener to receive incoming messages.
proto.addListener(new Pushable()
{
public void receiveMessage (Message m)
{
System.out.println (m.renderAsString());
}
});
// Log in
proto.console ("/user joebob");
proto.console ("/password opensaysme");
proto.connect();
// Send a message to the default recipient.
proto.getDefaultRecipient().sendReply ("Hello");
// poll everyone's status:
Enumeration enum = proto.getBuddies();
while (enum.hasMoreElements())
{
Recipient buddy = (Recipient) enum.nextElement();
Status status = proto.getStatusForBuddy(buddy);
System.err.println (buddy.getDescription() + ": "
+ status.getDescription());
}
}
}
Example: IRC
Here example, using the IRC client, of praya in use.
import wtanaka.praya.*;
import wtanaka.praya.obj.*;
import wtanaka.praya.irc.*;
import java.io.*;
import java.util.*;
public class IRCExample
{
public static void main (String[] args) throws IOException,
InterruptedException, NotSentException, IllegalCommandException
{
// Construct a new Protocol instance.
Protocol proto = new IRCClient();
// Add a listener to receive incoming messages.
proto.addListener(new Pushable()
{
public void receiveMessage (Message m)
{
System.out.println (m.renderAsString());
}
});
// Log in
proto.console ("/server irc.linux.com");
proto.console ("/nick prayatest");
proto.connect();
Thread.sleep (2000);
// send myself a message
Recipient me = new IRCUserViaPrivMsg (proto, "prayatest");
me.sendReply ("This is a test message");
Thread.sleep (2000);
// join a channel
proto.console ("/join #sourceforge");
// poll everyone's status:
Enumeration enum = proto.getBuddies();
while (enum.hasMoreElements())
{
Recipient buddy = (Recipient) enum.nextElement();
Status status = proto.getStatusForBuddy(buddy);
System.err.println (buddy.getDescription() + ": "
+ status.getDescription());
}
Thread.sleep (2000);
proto.console ("/leave #sourceforge");
Thread.sleep (2000);
proto.disconnect();
}
}
Example: DICT
Here example, using the DICT client, of praya in use.
import wtanaka.praya.*;
import wtanaka.praya.obj.*;
import wtanaka.praya.dict.*;
import java.io.*;
import java.util.*;
public class DictExample
{
public static void main (String[] args) throws IOException,
InterruptedException, NotSentException, IllegalCommandException
{
// Construct a new Protocol instance.
Protocol proto = new DictClient();
// Add a listener to receive incoming messages.
proto.addListener(new Pushable()
{
public void receiveMessage (Message m)
{
System.out.println (m.renderAsString());
}
});
// Connect
proto.connect();
proto.console ("/define llama");
Thread.sleep (2000);
proto.disconnect();
}
}
Wesley Tanaka