import java.util.Enumeration; import java.io.IOException; import java.io.FileInputStream; import java.net.URL; import java.net.MalformedURLException; import java.util.Hashtable; import java.util.Properties; import lava.net.common.UNA; import lava.net.common.UNL; import lava.net.mmp.MMPCenter; import lava.net.psyc.PSYCDeliveryException; import lava.net.psyc.PSYCMessageCenter; import lava.net.psyc.UNI; import lava.net.psyc.packages.Echo; import lava.net.psyc.packages.Trace; import lava.net.psyc.packages.Statistics; import lava.net.psyc.packages.LinkServer; import lava.net.psyc.packages.LinkServerListener; import lava.net.psyc.packages.Conferencing; import lava.net.psyc.packages.ConferencingListener; /** * **/ public class PSYCPlace implements LinkServerListener, ConferencingListener { /** * **/ private PSYCMessageCenter center = null; /** * **/ private Statistics stats = null; /** * **/ private LinkServer members = null; /** * **/ private Conferencing conf = null; /** * **/ private String context = null; /** * **/ public PSYCPlace() { this (null); } /** * **/ public PSYCPlace(MMPCenter mmpCenter) { this (mmpCenter,null,"myPlace"); } /** * **/ public PSYCPlace(MMPCenter mmpCenter, Properties settings, String name) { if(settings == null) { settings = new Properties(); try { settings.load(new FileInputStream("server.config")); } catch(IOException e) { } } name = "psyc.server.places." + name + "."; stats = new Statistics(); stats.addEvent("Statistics package created."); center = new PSYCMessageCenter(null,mmpCenter); stats.addEvent("PSYC system is up."); center.setName(null,settings.getProperty(name + "name")); center.setDescription(null,settings.getProperty(name + "description")); center.setNickname(null,settings.getProperty(name + "nickname")); try { center.setURLDescription(null,// new URL(settings.getProperty(name + "url"))); } catch(MalformedURLException e) { center.setURLDescription(null,null); } center.setHumanInformation(null,// settings.getProperty(name + "information")); center.setContentType(null,"text/plain"); center.setGreeting(settings.getProperty(name + "greetingMethod"),// settings.getProperty(name + "greetingBody")); center.addPackage(new Echo()); stats.addEvent("PSYC system included Echo package."); center.addPackage(new Trace()); stats.addEvent("PSYC system included Trace package."); center.addPackage(stats); stats.addEvent("PSYC system included Statistics package."); center.addPackage(members = new LinkServer(this)); stats.addEvent("PSYC system included Link Server package."); center.addPackage(conf = new Conferencing(this)); context = conf.createPlace(null,// true,false,false,false,false,false); stats.addEvent("PSYC system included Conferencing package."); stats.addEvent("PSYC system completed initialization."); } /** * **/ public PSYCMessageCenter getCenter() { return center; } /** * **/ private Hashtable linked = new Hashtable(); /** * **/ public void peerLinkRequest(UNL client, String body) { stats.addEvent(1,"" + client + ": wants to connect" + // (body == null || body.length() <= 0 ? "." : ": " + body)); if(client.getContext() != null && !client.getContext().equals(context)) { members.unlink(client); return; } members.link(client); UNI identification = center.getIdentification(client); if(identification == null) identification = new UNI(client); client = client.addContext(context); Hashtable locations = new Hashtable(); locations.put(client,client); conf.augmentMember(context,identification,null,locations,// true,true,false); center.assignVariable(client,conf.structGroupTag,// conf.getGroupValue(context),true); } /** * **/ public void peerUnlinked(UNL client, String body) { stats.addEvent(1,"" + client + " gots disconnected" + // (body == null || body.length() <= 0 ? "." : ": " + body)); UNI identification = center.getIdentification(client); if(identification == null) identification = new UNI(client); conf.diminishMember(context,identification,null,null,// false,false,false); } /** * **/ public void contextIntroduced(UNL source, String context) { } /** * **/ public void placeEntered(String context, UNI user) { stats.addEvent(1,"" + user + " entered place " + context); } /** * **/ public void placeLeft(String context, UNI user) { stats.addEvent(1,"" + user + " left place " + context); Enumeration e = conf.getLocations(context,user); for(;e.hasMoreElements();) { UNL location = (UNL)e.nextElement(); center.diminishVariable(location,conf.structGroupTag,null,true); if(members.isLinked(location)) members.unlink(location); location = location.withoutContext(); if(members.isLinked(location)) members.unlink(location); } } /** * **/ public void placeDeleted(String context) { stats.addEvent(3,"place " + context + // " deleted. This should not happen!"); } /** * **/ public void memberChanged(String context, UNI user, UNL multicaster, // Hashtable locations, boolean speak, boolean listen, boolean authority) { } /** * **/ public void placePropertiesChanged(String context, // boolean allowExternals, // boolean speakersAddSpeakers, boolean speakersAddListeners, // boolean listenersAddListeners, // boolean speakersRemoveSpeakers, boolean speakersRemoveListeners) { } /** * **/ public void conversationPublic(String context, UNI user, String message) { } /** * **/ public void conversationPager(UNL user, String message) { } /** * **/ public void conversationPrivate(UNL user, String message) { } /** * **/ public void conversationEcho(String message) { } /** * **/ public static void main(String args[]) { PSYCPlace s = new PSYCPlace(); } }