changed folder name
This commit is contained in:
parent
4503531ec9
commit
80c6a52c69
73 changed files with 0 additions and 0 deletions
193
src/zutil/net/ssdp/SSDPClient.java
Normal file
193
src/zutil/net/ssdp/SSDPClient.java
Normal file
|
|
@ -0,0 +1,193 @@
|
|||
package zutil.net.ssdp;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.InetAddress;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import zutil.io.StringOutputStream;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.net.http.HTTPHeaderParser;
|
||||
import zutil.net.http.HttpPrintStream;
|
||||
import zutil.net.threaded.ThreadedUDPNetwork;
|
||||
import zutil.net.threaded.ThreadedUDPNetworkThread;
|
||||
|
||||
/**
|
||||
* An SSDP client class that will request
|
||||
* service information.
|
||||
*
|
||||
* @author Ziver
|
||||
*/
|
||||
public class SSDPClient extends ThreadedUDPNetwork implements ThreadedUDPNetworkThread{
|
||||
public static final Logger logger = LogUtil.getLogger();
|
||||
// Contains all the received services
|
||||
private HashMap<String, LinkedList<SSDPServiceInfo>> services_st;
|
||||
private HashMap<String, SSDPServiceInfo> services_usn;
|
||||
|
||||
|
||||
public static void main(String[] args) throws IOException{
|
||||
System.out.println(LogUtil.getCalingClass());
|
||||
LogUtil.setGlobalLevel(Level.FINEST);
|
||||
SSDPClient ssdp = new SSDPClient();
|
||||
ssdp.requestService("upnp:rootdevice");
|
||||
ssdp.start();
|
||||
|
||||
for(int i=0; true ;++i){
|
||||
while( i==ssdp.getServicesCount("upnp:rootdevice") ){ try{Thread.sleep(100);}catch(Exception e){} }
|
||||
logger.log(Level.FINEST, "************************" );
|
||||
logger.log(Level.FINEST, ""+ssdp.getServices("upnp:rootdevice").get(i) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new instance of this class. An UDP
|
||||
* listening socket at the SSDP port.
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public SSDPClient() throws IOException{
|
||||
super( null );
|
||||
super.setThread( this );
|
||||
|
||||
services_st = new HashMap<String, LinkedList<SSDPServiceInfo>>();
|
||||
services_usn = new HashMap<String, SSDPServiceInfo>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends an request for an service
|
||||
*
|
||||
* @param st is the SearchTarget of the service
|
||||
*
|
||||
* ***** REQUEST:
|
||||
* M-SEARCH * HTTP/1.1
|
||||
* Host: 239.255.255.250:reservedSSDPport
|
||||
* Man: "ssdp:discover"
|
||||
* ST: ge:fridge
|
||||
* MX: 3
|
||||
*
|
||||
*/
|
||||
public void requestService(String st){
|
||||
try {
|
||||
services_st.put( st, new LinkedList<SSDPServiceInfo>() );
|
||||
|
||||
// Generate an SSDP discover message
|
||||
StringOutputStream msg = new StringOutputStream();
|
||||
HttpPrintStream http = new HttpPrintStream( msg, HttpPrintStream.HTTPMessageType.REQUEST );
|
||||
http.setRequestType("M-SEARCH");
|
||||
http.setRequestURL("*");
|
||||
http.setHeader("Host", SSDPServer.SSDP_MULTICAST_ADDR+":"+SSDPServer.SSDP_PORT );
|
||||
http.setHeader("ST", st );
|
||||
http.setHeader("Man", "\"ssdp:discover\"" );
|
||||
http.setHeader("MX", "3" );
|
||||
|
||||
http.close();
|
||||
logger.log(Level.FINEST, "***** REQUEST: \n"+msg);
|
||||
byte[] data = msg.toString().getBytes();
|
||||
DatagramPacket packet = new DatagramPacket(
|
||||
data, data.length,
|
||||
InetAddress.getByName( SSDPServer.SSDP_MULTICAST_ADDR ),
|
||||
SSDPServer.SSDP_PORT );
|
||||
super.send( packet );
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of received services by
|
||||
* the given search target.
|
||||
*
|
||||
* @param st is the search target
|
||||
* @return a list of received services
|
||||
*/
|
||||
public LinkedList<SSDPServiceInfo> getServices(String st){
|
||||
return services_st.get( st );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount of services in the search target
|
||||
*
|
||||
* @param st is the search target
|
||||
* @return the amount of services
|
||||
*/
|
||||
public int getServicesCount(String st){
|
||||
if( services_st.containsKey( st ) ){
|
||||
return services_st.get( st ).size();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a service with the given USN.
|
||||
*
|
||||
* @param usn is the unique identifier for the service
|
||||
* @return an service, null if there is no such service
|
||||
*/
|
||||
public SSDPServiceInfo getService(String usn){
|
||||
return services_usn.get( usn );
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all the received information of the services
|
||||
*/
|
||||
public void clearServices(){
|
||||
services_usn.clear();
|
||||
services_st.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for responses
|
||||
*
|
||||
* ***** RESPONSE;
|
||||
* HTTP/1.1 200 OK
|
||||
* Ext:
|
||||
* Cache-Control: no-cache="Ext", max-age = 5000
|
||||
* ST: ge:fridge
|
||||
* USN: uuid:abcdefgh-7dec-11d0-a765-00a0c91e6bf6
|
||||
* Location: http://localhost:80
|
||||
*/
|
||||
public void receivedPacket(DatagramPacket packet, ThreadedUDPNetwork network) {
|
||||
HTTPHeaderParser header = new HTTPHeaderParser( new String( packet.getData() ) );
|
||||
logger.log(Level.FINEST, "*********** Recived\n"+header);
|
||||
|
||||
String usn = header.getHeader("USN");
|
||||
String st = header.getHeader("ST");
|
||||
StandardSSDPInfo service;
|
||||
// Get existing service
|
||||
if( services_usn.containsKey( usn )){
|
||||
service = (StandardSSDPInfo)services_usn.get( usn );
|
||||
}
|
||||
// Add new service
|
||||
else{
|
||||
service = new StandardSSDPInfo();
|
||||
services_usn.put( usn, service);
|
||||
if( !services_st.containsKey(st) )
|
||||
services_st.put( st, new LinkedList<SSDPServiceInfo>() );
|
||||
services_st.get( header.getHeader("ST") ).add( service );
|
||||
}
|
||||
|
||||
service.setLocation( header.getHeader("LOCATION") );
|
||||
service.setST( st );
|
||||
service.setUSN( usn );
|
||||
service.setExpirationTime(
|
||||
System.currentTimeMillis() +
|
||||
1000 * getCacheTime(header.getHeader("Cache-Control")) );
|
||||
logger.log(Level.FINEST, "*********** Recived\n"+service);
|
||||
}
|
||||
|
||||
private long getCacheTime(String cache_control){
|
||||
long ret = 0;
|
||||
String[] tmp = cache_control.split(",");
|
||||
for( String element : tmp ){
|
||||
element = element.replaceAll("\\s", "").toLowerCase();
|
||||
if( element.startsWith("max-age=") ){
|
||||
ret = Long.parseLong( element.substring( "max-age=".length() ) );
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
309
src/zutil/net/ssdp/SSDPServer.java
Normal file
309
src/zutil/net/ssdp/SSDPServer.java
Normal file
|
|
@ -0,0 +1,309 @@
|
|||
package zutil.net.ssdp;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.InetAddress;
|
||||
import java.util.HashMap;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import zutil.io.MultiPrintStream;
|
||||
import zutil.io.StringOutputStream;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.net.http.HTTPHeaderParser;
|
||||
import zutil.net.http.HttpPrintStream;
|
||||
import zutil.net.threaded.ThreadedUDPNetworkThread;
|
||||
import zutil.net.threaded.ThreadedUDPNetwork;
|
||||
|
||||
/**
|
||||
* A Server class that announces an service by the SSDP
|
||||
* protocol specified at:
|
||||
* http://coherence.beebits.net/chrome/site/draft-cai-ssdp-v1-03.txt
|
||||
* ftp://ftp.pwg.org/pub/pwg/www/hypermail/ps/att-0188/01-psi_SSDP.pdf
|
||||
*
|
||||
* @author Ziver
|
||||
*
|
||||
* ********* Message clarification:
|
||||
* ****** Incoming:
|
||||
* ST: Search Target, this is object of the discovery request, (e.g., ssdp:all, etc.)
|
||||
* HOST: This is the SSDP multicast address
|
||||
* MAN: Description of packet type, (e.g., "ssdp:discover", )
|
||||
* MX: Wait these few seconds and then send response
|
||||
*
|
||||
* ****** Outgoing:
|
||||
* EXT: required by HTTP - not used with SSDP
|
||||
* SERVER: informational
|
||||
* LOCATION: This is the URL to request the QueryEndpointsInterface endpoint
|
||||
* USN: advertisement UUID
|
||||
* CACHE-CONTROL: max-age = seconds until advertisement expires
|
||||
* NT: Notify target same as ST
|
||||
* NTS: same as Man but for Notify messages
|
||||
*/
|
||||
public class SSDPServer extends ThreadedUDPNetwork implements ThreadedUDPNetworkThread{
|
||||
public static final Logger logger = LogUtil.getLogger();
|
||||
public static final String SERVER_INFO = "SSDP Java Server by Ziver Koc";
|
||||
public static final int DEFAULT_CACHE_TIME = 60*30; // 30 min
|
||||
public static final int BUFFER_SIZE = 512;
|
||||
public static final String SSDP_MULTICAST_ADDR = "239.255.255.250";
|
||||
public static final int SSDP_PORT = 1900;
|
||||
|
||||
// instance specific values
|
||||
private int cache_time;
|
||||
private NotifyTimer notifyTimer = null;
|
||||
/** HashMap that contains services as < SearchTargetName, SSDPServiceInfo > */
|
||||
private HashMap<String, SSDPServiceInfo> services;
|
||||
|
||||
|
||||
public static void main(String[] args) throws IOException{
|
||||
SSDPServer ssdp = new SSDPServer();
|
||||
StandardSSDPInfo service = new StandardSSDPInfo();
|
||||
service.setLocation("nowhere");
|
||||
service.setST("upnp:rootdevice");
|
||||
ssdp.addService(service);
|
||||
ssdp.start();
|
||||
MultiPrintStream.out.println("SSDP Server running");
|
||||
}
|
||||
|
||||
public SSDPServer() throws IOException{
|
||||
super( null, SSDP_MULTICAST_ADDR, SSDP_PORT );
|
||||
super.setThread( this );
|
||||
|
||||
services = new HashMap<String, SSDPServiceInfo>();
|
||||
|
||||
setChacheTime( DEFAULT_CACHE_TIME );
|
||||
enableNotify( true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an service that will be announced.
|
||||
*
|
||||
* @param searchTarget is the ST value in SSDP
|
||||
* @param location is the location of the service
|
||||
*/
|
||||
public void addService(SSDPServiceInfo service){
|
||||
services.put( service.getSearchTarget(), service );
|
||||
}
|
||||
/**
|
||||
* Remove a service from being announced. This function will
|
||||
* send out an byebye message to the clients that the service is down.
|
||||
*
|
||||
* @param searchTarget is the ST value in SSDP
|
||||
*/
|
||||
public void removeService(String searchTarget){
|
||||
sendByeBye( searchTarget );
|
||||
services.remove( searchTarget );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cache time that will be sent to
|
||||
* the clients. If notification is enabled then an
|
||||
* notification message will be sent every cache_time/2 seconds
|
||||
*
|
||||
* @param time is the time in seconds
|
||||
*/
|
||||
public void setChacheTime(int time){
|
||||
cache_time = time;
|
||||
if( isNotifyEnabled() ){
|
||||
enableNotify(false);
|
||||
enableNotify(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable or disable notification messages to clients
|
||||
* every cache_time/2 seconds
|
||||
*/
|
||||
public void enableNotify(boolean enable){
|
||||
if( enable && notifyTimer==null ){
|
||||
notifyTimer = new NotifyTimer();
|
||||
Timer timer = new Timer();
|
||||
timer.schedule(new NotifyTimer(), 0, cache_time*1000/2);
|
||||
}else if( !enable && notifyTimer!=null ){
|
||||
notifyTimer.cancel();
|
||||
notifyTimer = null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return if notification messages is enabled
|
||||
*/
|
||||
public boolean isNotifyEnabled(){
|
||||
return notifyTimer != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the incoming packets like this:
|
||||
*
|
||||
* ***** REQUEST:
|
||||
* M-SEARCH * HTTP/1.1
|
||||
* Host: 239.255.255.250:reservedSSDPport
|
||||
* Man: "ssdp:discover"
|
||||
* ST: ge:fridge
|
||||
* MX: 3
|
||||
*
|
||||
* ***** RESPONSE;
|
||||
* HTTP/1.1 200 OK
|
||||
* Ext:
|
||||
* Cache-Control: no-cache="Ext", max-age = 5000
|
||||
* ST: ge:fridge
|
||||
* USN: uuid:abcdefgh-7dec-11d0-a765-00a0c91e6bf6
|
||||
* Location: http://localhost:80
|
||||
*
|
||||
*/
|
||||
public void receivedPacket(DatagramPacket packet, ThreadedUDPNetwork network) {
|
||||
try {
|
||||
String msg = new String( packet.getData() );
|
||||
|
||||
HTTPHeaderParser header = new HTTPHeaderParser( msg );
|
||||
logger.log(Level.FINEST, "**** Received:\n"+header);
|
||||
|
||||
// ******* Respond
|
||||
// Check that the message is an ssdp discovery message
|
||||
if( header.getRequestType().equalsIgnoreCase("M-SEARCH") ){
|
||||
String man = header.getHeader("Man").replace("\"", "");
|
||||
String st = header.getHeader("ST");
|
||||
// Check that its the correct URL and that its an ssdp:discover message
|
||||
if( header.getRequestURL().equals("*") && man.equalsIgnoreCase("ssdp:discover") ){
|
||||
// Check if the requested service exists
|
||||
if( services.containsKey( st ) ){
|
||||
// Generate the SSDP response
|
||||
StringOutputStream response = new StringOutputStream();
|
||||
HttpPrintStream http = new HttpPrintStream( response );
|
||||
http.setStatusCode(200);
|
||||
http.setHeader("Server", SERVER_INFO );
|
||||
http.setHeader("ST", st );
|
||||
http.setHeader("Location", services.get(st).getLocation() );
|
||||
http.setHeader("EXT", "" );
|
||||
http.setHeader("Cache-Control", "max-age = "+cache_time );
|
||||
http.setHeader("USN", services.get(st).getUSN() );
|
||||
|
||||
http.close();
|
||||
logger.log(Level.FINEST, "********** Response:\n"+response);
|
||||
byte[] data = response.toString().getBytes();
|
||||
packet = new DatagramPacket(
|
||||
data, data.length,
|
||||
packet.getAddress(),
|
||||
packet.getPort());
|
||||
network.send( packet );
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This thread is a timer task that sends an
|
||||
* notification message to the network every
|
||||
* cache_time/2 seconds.
|
||||
*
|
||||
* @author Ziver
|
||||
*/
|
||||
private class NotifyTimer extends TimerTask {
|
||||
public void run(){
|
||||
sendNotify();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Sends keepalive messages to update the cache of the clients
|
||||
*/
|
||||
public void sendNotify(){
|
||||
for(String st : services.keySet()){
|
||||
sendNotify( st );
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Sends an keepalive message to update the cache of the clients
|
||||
*
|
||||
* @param searchTarget is the ST value of the service
|
||||
*
|
||||
* ********** Message ex:
|
||||
* NOTIFY * HTTP/1.1
|
||||
* Host: 239.255.255.250:reservedSSDPport
|
||||
* NT: blenderassociation:blender
|
||||
* NTS: ssdp:alive
|
||||
* USN: someunique:idscheme3
|
||||
* Location: http://localhost:80
|
||||
* Cache-Control: max-age = 7393
|
||||
*/
|
||||
public void sendNotify(String searchTarget){
|
||||
try {
|
||||
// Generate the SSDP response
|
||||
StringOutputStream msg = new StringOutputStream();
|
||||
HttpPrintStream http = new HttpPrintStream( msg, HttpPrintStream.HTTPMessageType.REQUEST );
|
||||
http.setRequestType("NOTIFY");
|
||||
http.setRequestURL("*");
|
||||
http.setHeader("Server", SERVER_INFO );
|
||||
http.setHeader("Host", SSDP_MULTICAST_ADDR+":"+SSDP_PORT );
|
||||
http.setHeader("NT", searchTarget );
|
||||
http.setHeader("NTS", "ssdp:alive" );
|
||||
http.setHeader("Location", services.get(searchTarget).getLocation() );
|
||||
http.setHeader("Cache-Control", "max-age = "+cache_time );
|
||||
http.setHeader("USN", services.get(searchTarget).getUSN() );
|
||||
|
||||
http.close();
|
||||
logger.log(Level.FINEST, "******** Notification:\n"+msg);
|
||||
byte[] data = msg.toString().getBytes();
|
||||
DatagramPacket packet = new DatagramPacket(
|
||||
data, data.length,
|
||||
InetAddress.getByName( SSDP_MULTICAST_ADDR ),
|
||||
SSDP_PORT );
|
||||
super.send( packet );
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Shutdown message is sent to the clients that all
|
||||
* the service is shutting down.
|
||||
*/
|
||||
public void sendByeBye(){
|
||||
for(String st : services.keySet()){
|
||||
sendByeBye( st );
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Shutdown message is sent to the clients that the service is shutting down
|
||||
*
|
||||
* @param searchTarget is the ST value of the service
|
||||
*
|
||||
* ********** Message ex:
|
||||
* NOTIFY * HTTP/1.1
|
||||
* Host: 239.255.255.250:reservedSSDPport
|
||||
* NT: someunique:idscheme3
|
||||
* NTS: ssdp:byebye
|
||||
* USN: someunique:idscheme3
|
||||
*/
|
||||
public void sendByeBye(String searchTarget){
|
||||
try {
|
||||
// Generate the SSDP response
|
||||
StringOutputStream msg = new StringOutputStream();
|
||||
HttpPrintStream http = new HttpPrintStream( msg, HttpPrintStream.HTTPMessageType.REQUEST );
|
||||
http.setRequestType("NOTIFY");
|
||||
http.setRequestURL("*");
|
||||
http.setHeader("Server", SERVER_INFO );
|
||||
http.setHeader("Host", SSDP_MULTICAST_ADDR+":"+SSDP_PORT );
|
||||
http.setHeader("NT", searchTarget );
|
||||
http.setHeader("NTS", "ssdp:byebye" );
|
||||
http.setHeader("USN", services.get(searchTarget).getUSN() );
|
||||
|
||||
http.close();
|
||||
logger.log(Level.FINEST, "******** ByeBye:\n"+msg);
|
||||
byte[] data = msg.toString().getBytes();
|
||||
DatagramPacket packet = new DatagramPacket(
|
||||
data, data.length,
|
||||
InetAddress.getByName( SSDP_MULTICAST_ADDR ),
|
||||
SSDP_PORT );
|
||||
super.send( packet );
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
35
src/zutil/net/ssdp/SSDPServiceInfo.java
Normal file
35
src/zutil/net/ssdp/SSDPServiceInfo.java
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package zutil.net.ssdp;
|
||||
|
||||
/**
|
||||
* This class contains information about a service from
|
||||
* or through the SSDP protocol
|
||||
*
|
||||
* @author Ziver
|
||||
*/
|
||||
public interface SSDPServiceInfo {
|
||||
|
||||
/**
|
||||
* @return The URL to the Service, e.g. "http://192.168.0.1:80/index.html"
|
||||
*/
|
||||
public String getLocation();
|
||||
|
||||
/**
|
||||
* @return the Search Target, e.g. "upnp:rootdevice"
|
||||
*/
|
||||
public String getSearchTarget();
|
||||
|
||||
/**
|
||||
* @return the expiration time for the values in this object
|
||||
*/
|
||||
public long getExpirationTime();
|
||||
|
||||
/**
|
||||
* @return the USN value, e.g. "uuid:abcdefgh-7dec-11d0-a765-00a0c91e6bf6 "
|
||||
*/
|
||||
public String getUSN();
|
||||
|
||||
/**
|
||||
* @return only the USN UUID String
|
||||
*/
|
||||
public String getUUID();
|
||||
}
|
||||
98
src/zutil/net/ssdp/StandardSSDPInfo.java
Normal file
98
src/zutil/net/ssdp/StandardSSDPInfo.java
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
package zutil.net.ssdp;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* This class contains information about a service from
|
||||
* or through the SSDP protocol
|
||||
*
|
||||
* @author Ziver
|
||||
*/
|
||||
public class StandardSSDPInfo implements SSDPServiceInfo{
|
||||
private String location;
|
||||
private String st;
|
||||
private String usn;
|
||||
private long expiration_time;
|
||||
|
||||
/**
|
||||
* @param l is the value to set the Location variable
|
||||
*/
|
||||
public void setLocation(String l) {
|
||||
location = l;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param st is the value to set the SearchTarget variable
|
||||
*/
|
||||
public void setST(String st) {
|
||||
this.st = st;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param usn is the value to set the USN variable
|
||||
*/
|
||||
protected void setUSN(String usn) {
|
||||
this.usn = usn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param time sets the expiration time of values in this object
|
||||
*/
|
||||
protected void setExpirationTime(long time) {
|
||||
expiration_time = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The URL to the Service, e.g. "http://192.168.0.1:80/index.html"
|
||||
*/
|
||||
public String getLocation(){
|
||||
return location;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Search Target, e.g. "upnp:rootdevice"
|
||||
*/
|
||||
public String getSearchTarget(){
|
||||
return st;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the expiration time for the values in this object
|
||||
*/
|
||||
public long getExpirationTime(){
|
||||
return expiration_time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the USN value, e.g. "uuid:abcdefgh-7dec-11d0-a765-00a0c91e6bf6 "
|
||||
*/
|
||||
public String getUSN(){
|
||||
if( usn==null )
|
||||
usn = genUSN();
|
||||
return usn+"::"+st;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return only the USN UUID String
|
||||
*/
|
||||
public String getUUID(){
|
||||
if( usn==null )
|
||||
usn = genUSN();
|
||||
return usn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an unique USN for the service
|
||||
*
|
||||
* @param searchTarget is the service ST name
|
||||
* @return an unique string that corresponds to the service
|
||||
*/
|
||||
private String genUSN(){
|
||||
return "uuid:" + UUID.nameUUIDFromBytes( (st+location+Math.random()).getBytes() );
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return "USN: "+usn+"\nLocation: "+location+"\nST: "+st+"\nExpiration-Time: "+new Date(expiration_time);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue