Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) FuseSource, Inc. http://fusesource.com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.fusesource.fabric.dosgi;
 
 
 import  org.fusesource.fabric.zookeeper.IZKClient;
 import  org.linkedin.zookeeper.client.LifecycleListener;
 import  org.osgi.framework.BundleContext;
 import  org.osgi.framework.ServiceReference;
 
 public class Activator implements LifecycleListener {
 
     private BundleContext bundleContext;
     private Manager manager;
     private String uri;
     private String exportedAddress;
     private long timeout = ..toMillis(5);
     private ServiceReference reference;
     private IZKClient zookeeper;
 
     public void setBundleContext(BundleContext bundleContext) {
         this. = bundleContext;
     }
 
     public void setUri(String uri) {
         this. = uri;
     }
 
     public void setExportedAddress(String exportedAddress) {
         this. = exportedAddress;
     }
 
     public void setTimeout(long timeout) {
         this. = timeout;
     }
 
     public void destroy() {
         destroyManager();
         if ( != null) {
             ServiceReference ref = ;
              = null;
              = null;
             this..ungetService(ref);
         }
     }
 
     protected void destroyManager() {
         if ( != null) {
             Manager mgr = ;
              = null;
             mgr.destroy();
         }
     }
 
     public void registerZooKeeper(ServiceReference ref) {
         destroy();
         try {
              = ref;
              = (IZKClient) this..getService();
             .registerListener(this);
         } catch (Exception e) {
             throw new RuntimeException("Unable to start DOSGi service: " + e.getMessage(), e);
         }
     }
 
     public void unregisterZooKeeper(ServiceReference reference) {
         destroy();
     }
 
     @Override
     public void onConnected() {
         destroyManager();
         try {
              = new Manager(this.);
             .init();
         } catch (Exception e) {
             throw new RuntimeException("Unable to start DOSGi service: " + e.getMessage(), e);
         }
     }
 
     @Override
     public void onDisconnected() {
         destroyManager();
    }
New to GrepCode? Check out our FAQ X