[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[xmlblaster] Java and C#
- To: xmlblaster at server.xmlBlaster.org
- Subject: [xmlblaster] Java and C#
- From: Mohannad <r.mohannad at gmail.com>
- Date: Fri, 30 May 2008 10:54:11 +0300
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type; bh=cg3gMU3i9SexplJD6BZ+e+flf+e/LquoVF02SxSzHKE=; b=J+yH/sNz+GVG+uvm/4RRyHvmrMCDayuO09P7xpMZnrWVy9dcOAkMKQlU3d/WlxKqaczd0vGoflkyxgTzixsjjL22uGgxCyxGI9FUWeJVym132rKEuqROSRFH1NE7Vgd9Rb0fohSDh3/p3wtCThdA1I7wrsbp2JbkaPhuSTzOMIY=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type; b=umyXwSei/6/mC3b2jdaGdVBLsrIyPOE74SRKHgIFPlp6THc5++p8MVWIzCTIRfEzMMH8PcsrBkJcxqqXBxr6MLOpNNjXxRV+v1i1y5RbhC3Zzy6/VcOuehH1jJ+scPeHnFt1eOZFXRRAC36qeKNeisr/PweExaCCM4tTpDMYRKo=
- Reply-to: xmlblaster at server.xmlBlaster.org
- Sender: owner-xmlblaster at server.xmlBlaster.org
Dear sir,
I need to make a small communication using XMLblaster between two objects : Java and C#.
Mr.Zied made a file (Attached) for testing latency in Java and I need to make the same but in C# to make that small communication.
Could any body help please?
Thanks
Mohannad
import org.xmlBlaster.util.Global;
import org.xmlBlaster.util.SessionName;
import org.xmlBlaster.util.XmlBlasterException;
import org.xmlBlaster.client.qos.ConnectQos;
import org.xmlBlaster.client.qos.PublishQos;
import org.xmlBlaster.client.I_Callback;
import org.xmlBlaster.client.key.PublishKey;
import org.xmlBlaster.client.key.UpdateKey;
import org.xmlBlaster.client.qos.UpdateQos;
import org.xmlBlaster.client.I_XmlBlasterAccess;
import org.xmlBlaster.util.MsgUnit;
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import org.xmlBlaster.util.qos.address.Address;
import org.xmlBlaster.util.qos.address.CallbackAddress;
public class PingTest implements I_Callback
{
private String oid="test";
private Global glob;
I_XmlBlasterAccess con;
long fin = -1L;
long debut = -1L;
long latence = -1L;
static boolean t =true;
static PrintWriter output = null;
/* public static byte [] (byte y [], int n_byte){
byte [] x = new byte [n_byte];
for (int i = 0; i <n_byte; i++){
}
}*/
public PingTest(final Global glob) {
t = false;
try {
this.glob =glob;
// Parametre de connexion ( Obligatoire )
String[] args = { "-protocol", "XMLRPC",
"-dispatch/connection/plugin/xmlrpc/hostname", "172.16.128.43",
"-dispatch/connection/plugin/xmlrpc/port", "7766",
// "-dispatch/connection/plugin/xmlrpc/port","8080",
"-dispatch/connection/plugin/xmlrpc/localHostname", "10.13.17.73",
// "-dispatch/callback/plugin/xmlrpc/hostname","10.13.17.73",
// "-dispatch/connection/plugin/socket/localPort", "8888",
"-dispatch/callback/plugin/socket/port","3412"
};
// String[] args = { "-DORBInitRef.NameService=file:///var/new/dbs/naming_hat/env.iro",
// "-dispatch/callback/plugin/socket/port","3412"
// };
glob.init(args);
// Address address = new Address(glob);
// address.setType("SOCKET"); // force SOCKET protocol
// address.setRawAddress("socket://noty:9988"); // Address to find the server
con=glob.getXmlBlasterAccess();
ConnectQos qos = new ConnectQos(glob);
con.connect(qos, this); // Login to xmlBlaster, register for updates
System.out.println("Envoie d'un ping");
debut=System.currentTimeMillis();
System.out.println("debut : "+debut);
send("ping1234"); // send ping message
//subscribe
con.subscribe("<key oid='test'/>", "<qos/>");
}
catch (Exception e) {
System.err.println(e.getMessage());
}
}
void send(String cont)
{
PublishKey pk = new PublishKey(glob, oid, "text/xml", "1.0");
PublishQos pq = new PublishQos(glob);
pq.setPersistent(false);
byte [] content = cont.getBytes();
byte [] x = new byte [content.length *2];
for (int i = 0; i<(content.length *2);i++)
{
if (i < content.length )
x[i] = content[i];
else
x[i] = content[i/content.length];
}
System.out.println("The size................. is "+ x.length);
MsgUnit msgUnit = new MsgUnit(pk, content, pq);
try {
// publish
con.publish(msgUnit);
} catch (XmlBlasterException e) {
System.err.print(e);
}
}
//update : reception d'un message
public String update(String cbSessionId, UpdateKey updateKey, byte[] content,
UpdateQos updateQos)
{
String receive = new String(content);
if (receive.equals("pong1234"))
// if (receive.has)
{
fin=System.currentTimeMillis();
System.out.println("fin : "+fin);
latence = (fin-debut)/2;
System.out.println("latence : "+latence);
output.println("latence "+latence );
try {
con.erase("<key oid='HelloWorld2'/>", null);
} catch (XmlBlasterException e) {
e.printStackTrace();
}
con.disconnect(null);
t = true;
}
return "";
}
public static void main(String args[]) {
Global glob = new Global();
if (glob.init(args) != 0) { // Get help with -help
System.out.println(glob.usage());
System.out.println("Example: java HelloWorld2 -session.name Jack");
System.exit(1);
}
try{
output = new PrintWriter(new File
("data.txt"));
}
catch(FileNotFoundException e){
System.out.println("Problem opening files.");
}
PingTest ping = new PingTest(glob);
// send 50 messages
for (int i =0; i<50; i++)
{
while (!t){}
new PingTest(glob);
}
output.close();
}
}