package org.eclipse.ecf.provider.zookeeper.core;
import java.net.URI;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.UUID;
import org.eclipse.core.runtime.Assert;
import org.eclipse.ecf.discovery.IServiceInfo;
import org.eclipse.ecf.discovery.IServiceProperties;
import org.eclipse.ecf.discovery.ServiceInfo;
import org.eclipse.ecf.discovery.ServiceProperties;
import org.eclipse.ecf.discovery.identity.IServiceID;
import org.eclipse.ecf.discovery.identity.IServiceTypeID;
import org.eclipse.ecf.discovery.identity.ServiceIDFactory;
import org.eclipse.ecf.provider.zookeeper.core.internal.IService;
import org.eclipse.ecf.provider.zookeeper.node.internal.INode;
import org.eclipse.ecf.provider.zookeeper.util.Geo;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
private static final long serialVersionUID = 1001026250299416572L;
private String uuid;
private Properties properties = new Properties();
private static Map<String, IServiceInfo> publishedServices = new HashMap<String, IServiceInfo>();
private ServiceReference serviceReference;
private ServiceProperties serviceProperties;
Assert.isNotNull(ref);
this.serviceReference = ref;
this.uuid = UUID.randomUUID().toString();
String services[] = (String[]) this.serviceReference
.getProperty(Constants.OBJECTCLASS);
for (String k : this.serviceReference.getPropertyKeys()) {
Object value = this.serviceReference.getProperty(k);
if (value instanceof String
&& ((String) value).contains("localhost")) {
this.properties.put(k, ((String) value).replace("localhost",
Geo.getHost()));
continue;
}
this.properties.put(k, this.serviceReference.getProperty(k));
}
IServiceTypeID serviceTypeID = ServiceIDFactory
.getDefault()
.createServiceTypeID(
DiscoveryContainer.getSingleton().getConnectNamespace(),
services, IServiceTypeID.DEFAULT_PROTO);
serviceTypeID = new ZooServiceTypeID(
(DiscoveryNamespace) DiscoveryContainer.getSingleton()
.getConnectNamespace(), serviceTypeID,
this.serviceReference.getProperty(Constants.SERVICE_ID)
.toString());
serviceID = new ZooServiceID(DiscoveryContainer.getSingleton()
.getConnectNamespace(), serviceTypeID, Geo.getLocation());
super.properties = new ServiceProperties(this.properties);
this.properties.put(Constants.OBJECTCLASS, arrayToString(services));
this.properties.put(LOCATION, Geo.getLocation());
this.properties.put(WEIGHT, getWeight());
this.properties.put(PRIORITY, getPriority());
this.properties.put(NODE_PROPERTY_NAME_PROTOCOLS,
arrayToString(IServiceTypeID.DEFAULT_PROTO));
this.properties.put(NODE_PROPERTY_NAME_SCOPE,
arrayToString(IServiceTypeID.DEFAULT_SCOPE));
this.properties.put(NODE_PROPERTY_NAME_NA, IServiceTypeID.DEFAULT_NA);
publishedServices.put(serviceTypeID.getInternal(), this);
}
super(serviceInfo.getLocation(), serviceInfo.getServiceName(),
serviceInfo.getServiceID().getServiceTypeID(), serviceInfo
.getPriority(), serviceInfo.getWeight(), serviceInfo
.getServiceProperties());
this.uuid = UUID.randomUUID().toString();
this.properties
.put(NODE_PROPERTY_NAME_PROTOCOLS, arrayToString(getServiceID()
.getServiceTypeID().getProtocols()));
this.properties.put(NODE_PROPERTY_NAME_SCOPE,
arrayToString(getServiceID().getServiceTypeID().getScopes()));
this.properties.put(NODE_PROPERTY_SERVICES,
arrayToString(getServiceID().getServiceTypeID().getServices()));
this.properties.put(NODE_PROPERTY_NAME_NA, getServiceID()
.getServiceTypeID().getNamingAuthority());
this.properties.put(LOCATION, Geo.getLocation());
this.properties.put(WEIGHT, getWeight());
this.properties.put(PRIORITY, getPriority());
publishedServices.put(serviceInfo.getServiceID().getServiceTypeID()
.getInternal(), this);
}
return Collections.unmodifiableMap(publishedServices);
}
return publishedServices.remove(id);
}
return this.properties;
}
return this.uuid;
}
this.uuid = UUID.randomUUID().toString();
}
return serviceID.getLocation();
}
return serviceID;
}
return this.serviceProperties;
}
Assert.isTrue(o != null && o instanceof IServiceInfo,
"incompatible types for compare");
return this.getServiceID().getName().compareTo(
((IServiceInfo) o).getServiceID().getName());
}
return this.serviceReference;
}
return getPropertiesAsString().getBytes();
}
String props = "";
for (Object k : this.getProperties().keySet()) {
props += k + "=" + this.getProperties().get(k) + "\n";
}
return props;
}
return getNodeId() + INode._URI_ + Geo.getHost();
}
return INode.ROOT_SLASH + getPath();
}
return Geo.isLocal(getAbsolutePath());
}
return this;
}
String s = "";
for (String c : arr) {
s += c + " ";
}
return s;
}
}