* <em>from top to bottom</em>.
* Each layer can perform some initialization, e.g. create a multicast socket
*/
public void startStack(String cluster, Address local_addr) throws Exception {
if(stopped == false) return;
final AsciiString cluster_name=new AsciiString(cluster);
Protocol above_prot=null;
for(final Protocol prot: getProtocols()) {
if(prot instanceof TP) {
String singleton_name=((TP)prot).getSingletonName();
TP transport=(TP)prot;
if(transport.isSingleton() && cluster_name != null) {
final Map<AsciiString, Protocol> up_prots=transport.getUpProtocols();
synchronized(singleton_transports) {
synchronized(up_prots) {
Set<AsciiString> keys=up_prots.keySet();
if(keys.contains(cluster_name))
throw new IllegalStateException("cluster '" + cluster_name + "' is already connected to singleton " +
"transport: " + keys);
for(Iterator<Map.Entry<AsciiString,Protocol>> it=up_prots.entrySet().iterator(); it.hasNext();) {
Map.Entry<AsciiString,Protocol> entry=it.next();
Protocol tmp=entry.getValue();
if(tmp == above_prot) {
it.remove();
}
}
if(above_prot != null) {
TP.ProtocolAdapter ad=new TP.ProtocolAdapter(new AsciiString(cluster_name), local_addr, prot.getId(),
above_prot, prot,
transport.getThreadNamingPattern());
ad.setProtocolStack(above_prot.getProtocolStack());
above_prot.setDownProtocol(ad);
up_prots.put(cluster_name, ad);