«Содержание Введение 1 Системы мониторинга 1.1 Введение 1.2 Понятие систем мониторинга 1.3 Подсистемы мониторинга 1.3.1 Сбор данных 1.3.2 Хранение данных 1.3.3 Анализ данных 1.3.4 Отчетность 1.3.5 Оповещения 1.3.6 ...»
* You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2. * 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 com.googlecode.snoopyd.core.filter;
import com.googlecode.snoopyd.core.Kernel;
public abstract class AbstractKernelFilter implements KernelFilter { protected Kernel kernel;
public AbstractKernelFilter(Kernel kernel) { /** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.core.filter;
import com.googlecode.snoopyd.core.event.KernelEvent;
public interface KernelFilter { public static enum FilterAction {
ACCEPT, REJECT
public FilterAction accept(KernelEvent event);/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.core.filter;
import com.googlecode.snoopyd.core.Kernel;
import com.googlecode.snoopyd.core.event.KernelEvent;
import com.googlecode.snoopyd.core.event.KernelStateChangedEvent;
public class ToogleFilter extends AbstractKernelFilter implements KernelFilter { public ToogleFilter(Kernel kernel) { public FilterAction accept(KernelEvent event) { FilterAction action = FilterAction.ACCEPT;
if (event instanceof KernelStateChangedEvent && kernel.peek() instanceof KernelStateChangedEvent) { /** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.core.event;
import Ice.Identity;
public class ChildNodeDeadedEvent implements KernelEvent { private Ice.Identity identity;
public ChildNodeDeadedEvent(Identity identity) { public Ice.Identity identity() { public String name() { return this.getClass().getSimpleName();
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.core.event;
import Ice.Identity;
import com.googlecode.snoopyd.session.ISessionPrx;
public class ChildSessionRecivedEvent implements KernelEvent { private Ice.Identity identity;
private ISessionPrx session;
public ChildSessionRecivedEvent(Identity identity, ISessionPrx session) { public String name() { return this.getClass().getSimpleName();
public ISessionPrx session() { public Ice.Identity identity() { /** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.core.event;
import Ice.Identity;
import com.googlecode.snoopyd.session.ISessionPrx;
public class ChildSessionSendedEvent implements KernelEvent { private Identity identity;
private ISessionPrx session;
public ChildSessionSendedEvent(Identity identity, ISessionPrx session) { public String name() { return this.getClass().getSimpleName();
public ISessionPrx session() { public Ice.Identity identity() { /** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.core.event;
import java.util.Map;
public class DiscoverRecivedEvent implements KernelEvent { private Map context;
private Ice.Identity identity;
public DiscoverRecivedEvent(Ice.Identity identity, Map context) { public String name() { return this.getClass().getSimpleName();
public Map context() { public Ice.Identity identity() { /** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.core.event;
public class ExceptionEvent implements KernelEvent { private Throwable exception;
public ExceptionEvent(Throwable exception) { this.exception = exception;
public Throwable exception() { public String name() { return this.getClass().getSimpleName();
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.core.event;
public class ForceStartEvent implements KernelEvent { private String muid;
private String[] params;
public ForceStartEvent(String muid, String[] params) { public String muid() { public String[] params() { public String name() { return this.getClass().getSimpleName();
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.core.event;
public abstract class InvokationEvent implements KernelEvent, Runnable { public abstract void run();
public String name() { return InvokationEvent.class.getSimpleName();
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.core.event;
public interface KernelEvent { public String name();
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.core.event;
import java.util.Map;
public class KernelReconfiguredEvent implements KernelEvent { private Map configuration;
public KernelReconfiguredEvent(Map configuration) { this.configuration = configuration;
public Map configuration() { public String name() { return this.getClass().getSimpleName();
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.core.event;
import com.googlecode.snoopyd.core.state.KernelState;
public class KernelStateChangedEvent implements KernelEvent { private KernelState state;
public KernelStateChangedEvent(KernelState state) { public String name() { return this.getClass().getSimpleName();
public KernelState state() { /** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.core.event;
public class NetworkDisabledEvent implements KernelEvent { public String name() { return this.getClass().getSimpleName();
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.core.event;
public class NetworkEnabledEvent implements KernelEvent { public String name() { return this.getClass().getSimpleName();
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.core.event;
import Ice.Identity;
public class ParentNodeDeadedEvent implements KernelEvent { private Ice.Identity identity;
public ParentNodeDeadedEvent(Identity identity) { public Ice.Identity identity() { public String name() { return this.getClass().getSimpleName();
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.core.event;
import Ice.Identity;
import com.googlecode.snoopyd.session.IKernelSessionPrx;
public class ParentSessionRecivedEvent implements KernelEvent { private Ice.Identity identity;
private IKernelSessionPrx session;
public ParentSessionRecivedEvent(Identity identity, public String name() { return this.getClass().getSimpleName();
public Ice.Identity identity() { public IKernelSessionPrx sesssion() { /** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.core.event;
import com.googlecode.snoopyd.session.IKernelSessionPrx;
public class ParentSessionSendedEvent implements KernelEvent { private Ice.Identity identity;
private IKernelSessionPrx session;
public ParentSessionSendedEvent(Ice.Identity identity, IKernelSessionPrx session) { public String name() { return this.getClass().getSimpleName();
public IKernelSessionPrx session() { public Ice.Identity identity() { /** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.core.event;
import Ice.Identity;
public class ResultRecievedEvent implements KernelEvent { private Ice.Identity identity;
private String muid;
private String[] result;
public ResultRecievedEvent(Identity identity, String muid, String[] result) { public Ice.Identity identity() { public String muid() { public String[] result() { public String name() { return this.getClass().getSimpleName();
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.core.event;
public class ScheduleTimeComeEvent implements KernelEvent { private Ice.Identity identity;
private String muid;
private String[] params;
public ScheduleTimeComeEvent(Ice.Identity identity, String muid, String[] params) { public String name() { return this.getClass().getSimpleName();
public Ice.Identity identity() { public String muid() { public String[] params() { /** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.core.event;
import Ice.Identity;
public class ScheduleUpdatedEvent implements KernelEvent { public String name() { return this.getClass().getSimpleName();
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.core.event;
public class SnoopydStartedEvent implements KernelEvent { public String name() { return this.getClass().getSimpleName();
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.core.event;
public class SnoopydTerminatedEvent implements KernelEvent { public String name() { return this.getClass().getSimpleName();
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.driver;
import com.googlecode.snoopyd.core.Kernel;
public abstract class AbstractDriver implements Driver { protected Kernel kernel;
protected String name;
public AbstractDriver(String name, Kernel kernel) { public Kernel kernel() { public String name() { /** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.driver;
public interface Activable { public void activate();
public void deactivate();
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.driver;
import java.util.Map;
import org.apache.log4j.Logger;
import com.googlecode.snoopyd.Defaults;
import com.googlecode.snoopyd.core.Kernel;
import com.googlecode.snoopyd.core.event.ChildNodeDeadedEvent;
import com.googlecode.snoopyd.core.event.ParentNodeDeadedEvent;
import com.googlecode.snoopyd.core.state.ActiveState;
import com.googlecode.snoopyd.core.state.KernelListener;
import com.googlecode.snoopyd.core.state.KernelState;
import com.googlecode.snoopyd.core.state.PassiveState;
import com.googlecode.snoopyd.session.IKernelSessionPrx;
import com.googlecode.snoopyd.session.ISessionPrx;
import com.googlecode.snoopyd.util.Identities;
public class Aliver extends AbstractDriver implements Driver, Runnable, private static Logger logger = Logger.getLogger(Aliver.class);
private boolean started;
public Aliver(Kernel kernel) { super(Aliver.class.getSimpleName(), kernel);
public void run() { } catch (InterruptedException ex) { @Override public synchronized void start() { logger.debug("starting " + name);
Thread self = new Thread(this, Defaults.ALIVER_THREAD_NAME);
@Override public synchronized void stop() { logger.debug("stoping " + name);
} catch (InterruptedException e) { logger.warn(e.getMessage());
@Override public synchronized void restart() { logger.debug("restarting " + name);
@Override public boolean started() { @Override public void stateChanged(KernelState currentState) { if (currentState instanceof ActiveState /** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.driver;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.apache.log4j.Logger;
import com.googlecode.snoopyd.core.Kernel;
import com.googlecode.snoopyd.core.event.KernelReconfiguredEvent;
public class Configurer extends AbstractDriver implements Driver { private static Logger logger = Logger.getLogger(Configurer.class);
public Configurer(Kernel kernel) { super(Configurer.class.getSimpleName(), kernel);
public void reconfigure(Map configuration) { kernel.handle(new KernelReconfiguredEvent(configuration));
public Map configuration() { Properties prop = kernel.configuration();
prop.getProperty(key.toString()).toString());
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.driver;
import org.apache.log4j.Logger;
import com.googlecode.snoopyd.core.Kernel;
import com.googlecode.snoopyd.core.event.SnoopydTerminatedEvent;
public class Controller extends AbstractDriver implements Driver { private static Logger logger = Logger.getLogger(Controller.class);
public Controller(Kernel kernel) { super(Controller.class.getSimpleName(), kernel);
public void shutdown() { logger.debug("shutdown command received");
kernel.handle(new SnoopydTerminatedEvent());
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.driver;
import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
import com.googlecode.snoopyd.Defaults;
import com.googlecode.snoopyd.core.Kernel;
import com.googlecode.snoopyd.core.event.DiscoverRecivedEvent;
import com.googlecode.snoopyd.core.state.KernelListener;
import com.googlecode.snoopyd.core.state.KernelState;
import com.googlecode.snoopyd.core.state.OfflineState;
import com.googlecode.snoopyd.core.state.OnlineState;
import com.googlecode.snoopyd.core.state.SuspenseState;
import com.googlecode.snoopyd.util.Identities;
public class Discoverer extends AbstractDriver implements Driver, Runnable, private static Logger logger = Logger.getLogger(Discoverer.class);
private boolean started;
public Discoverer(Kernel kernel) { super(Discoverer.class.getSimpleName(), kernel);
public void discover(Ice.Identity identity, Map context) { StringBuilder sb = new StringBuilder();
Identities.toString(identity));
kernel.handle(new DiscoverRecivedEvent(identity, context));
public synchronized void start() { Thread self = new Thread(this, Defaults.DISCOVERER_THREAD_NAME);
public synchronized void stop() { public synchronized void restart() { logger.debug("restarting " + name);
public boolean started() { public void run() { com.googlecode.snoopyd.driver.IDiscovererPrxHelper.uncheckedCast(kernel.communicator().propertyToProxy( dmulticast = com.googlecode.snoopyd.driver.IDiscovererPrxHelper com.googlecode.snoopycp.core.IDiscovererPrxHelper.uncheckedCast(kernel.communicator().propertyToProxy( cpmulticast = com.googlecode.snoopycp.core.IDiscovererPrxHelper context.put("identity", Identities.toString(kernel.identity()));
context.put("primary", kernel.primaryPublishedEndpoints());
context.put("secondary", kernel.secondaryPublishedEndpoints());
context.put("state", kernel.state().getClass().getSimpleName());
} catch (InterruptedException ex) { public void stateChanged(KernelState currentState) { if (currentState instanceof OnlineState) { } else if (currentState instanceof OfflineState /** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.driver;
import com.googlecode.snoopyd.core.Kernel;
public interface Driver { public Kernel kernel();
public String name();
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.driver;
import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;
import com.googlecode.snoopyd.core.Kernel;
public class Hoster extends AbstractDriver implements Driver { private static Logger logger = Logger.getLogger(Hoster.class);
private Sigar sigar;
public Hoster(Kernel kernel) { super(Hoster.class.getSimpleName(), kernel);
public Map context() { Map cpu = sigar.getCpuInfoList()[0].toMap();
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.driver;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import org.apache.log4j.Logger;
import com.googlecode.snoopyd.Defaults;
import com.googlecode.snoopyd.core.Kernel;
import com.googlecode.snoopyd.core.state.ActiveState;
import com.googlecode.snoopyd.core.state.KernelListener;
import com.googlecode.snoopyd.core.state.KernelState;
import com.googlecode.snoopyd.core.state.PassiveState;
* TODO: remove it public class Invoker extends AbstractDriver implements Driver, Runnable, private static Logger logger = Logger.getLogger(Invoker.class);
private boolean started;
public Invoker(Kernel kernel) { super(Invoker.class.getSimpleName(), kernel);
public synchronized void invoke(Map invokation) { public synchronized void start() { Thread self = new Thread(this, Defaults.INVOKER_THREAD_NAME);
self.start();
@Override public synchronized void stop() { logger.debug("stoping " + name);
started = false;
} catch (InterruptedException e) { logger.warn(e.getMessage());
@Override public synchronized void restart() { logger.debug("restarting " + name);
@Override public boolean started() { return started;
@Override public void run() { public void stateChanged(KernelState currentState) { if (currentState instanceof ActiveState /** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.driver;
import java.util.Map;
import org.apache.log4j.Logger;
import com.googlecode.snoopyd.core.Kernel;
import com.googlecode.snoopyd.core.event.ForceStartEvent;
import com.googlecode.snoopymm.ModuleNotFoundException;
public class Moduler extends AbstractDriver implements Driver { private static Logger logger = Logger.getLogger(Moduler.class);
public Moduler(Kernel kernel) { super(Moduler.class.getSimpleName(), kernel);
public Map fetch() { return kernel.moduleManager().fetch();
com.googlecode.snoopyd.driver.ModuleNotFoundException { return kernel.moduleManager().launch(muid, params);
} catch (ModuleNotFoundException ex) { throw new com.googlecode.snoopyd.driver.ModuleNotFoundException();
public void deploy(String muid, String code) { kernel.moduleManager().deploy(muid, code);
public void undeploy(String muid) throws ModuleNotFoundException { kernel.moduleManager().undeploy(muid);
public void force(String muid, String[] params) { kernel.handle(new ForceStartEvent(muid, params));
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.driver;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import org.apache.log4j.Logger;
import com.googlecode.snoopyd.Defaults;
import com.googlecode.snoopyd.core.Kernel;
import com.googlecode.snoopyd.core.event.NetworkDisabledEvent;
import com.googlecode.snoopyd.core.event.NetworkEnabledEvent;
public class Networker extends AbstractDriver implements Driver, Activable, private static Logger logger = Logger.getLogger(Networker.class);
public static final int NETWORK_UNDEFINED = -1;
public static final int NETWORK_ENABLED = 0;
public static final int NETWORK_DISABLED = 1;
private int networkState;
private boolean started;
public Networker(Kernel kernel) { super(Networker.class.getSimpleName(), kernel);
this.networkState = NETWORK_UNDEFINED;
public void run() { !nic.isLoopback());
Thread.sleep(Defaults.NETWORKER_INTERVAL);
} catch (InterruptedException ignored) { synchronized (this) { @Override public synchronized void activate() { Thread self = new Thread(this);
self.start();
@Override public synchronized void deactivate() { /** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.driver;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import org.apache.log4j.Logger;
import com.googlecode.snoopyd.Defaults;
import com.googlecode.snoopyd.core.Kernel;
import com.googlecode.snoopyd.core.state.ActiveState;
import com.googlecode.snoopyd.core.state.KernelListener;
import com.googlecode.snoopyd.core.state.KernelState;
public class Resulter extends AbstractDriver implements Driver, Startable, private static Logger logger = Logger.getLogger(Resulter.class);
public static class Result { public Result(String hostname, String osname, String module, String[] result) private Connection connection;
private Queue pool;
private boolean started;
public Resulter(Kernel kernel) { super(Resulter.class.getSimpleName(), kernel);
this.pool = new LinkedList();
public synchronized void store(String hostname, String osname, String module, logger.debug("storing result " + Arrays.toString(result));
pool.offer(new Result(hostname, osname, module, result));
if (pool.size() > Defaults.RESULTER_THRESHHOLD) { public synchronized void start() { logger.debug("starting " + name);
kernel.configuration().getProperty("connectionstring");
logger.debug("use connection url: " + connectionurl);
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(connectionurl);
} catch (ClassNotFoundException ex) { } catch (SQLException ex) { logger.error(ex.getMessage());
Thread self = new Thread(this, Defaults.RESULTER_THREAD_NAME);
self.start();
@Override public synchronized void stop() { logger.debug("stoping " + name);
} catch (SQLException ex) { } catch (NullPointerException ex) { started = false;
} catch (InterruptedException e) { logger.warn(e.getMessage());
@Override public synchronized boolean started() { return started;
@Override public synchronized void restart() { logger.debug("restarting " + name);
@Override public void run() { \"%s\", \"%s\", \"%s\");", result.osname(), result.hostname(), result.module(), sb.toString()));
public void stateChanged(KernelState currentState) { if (currentState instanceof ActiveState) { /** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.driver;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.log4j.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentType;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import com.googlecode.snoopyd.Defaults;
import com.googlecode.snoopyd.core.Kernel;
import com.googlecode.snoopyd.core.event.ScheduleTimeComeEvent;
import com.googlecode.snoopyd.core.event.ScheduleUpdatedEvent;
import com.googlecode.snoopyd.core.state.ActiveState;
import com.googlecode.snoopyd.core.state.KernelListener;
import com.googlecode.snoopyd.core.state.KernelState;
import com.googlecode.snoopyd.util.Identities;
public class Scheduler extends AbstractDriver implements Driver, Startable, public static enum ScheduleState { public static class Schedule { public Map statetable() { public Map paramstable() { private static Logger logger = Logger.getLogger(Scheduler.class);
private Schedule self;
private HashMap childs;
private Map timers;
private boolean started;
public Scheduler(Kernel kernel) { super(Scheduler.class.getSimpleName(), kernel);
this.self = new Schedule();
this.childs = new HashMap();
this.timers = new HashMap();
loadScheduleConfig();
public void synchronize(Ice.Identity identity, ISchedulerPrx remoteScheduler) { logger.debug("synchronize shceduler with " Schedule childSchedule = new Schedule();
Map remoteTimetable = remoteScheduler.timetable();
Map remoteStatetable = remoteScheduler.statetable();
Map remoteParamtable = remoteScheduler.paramtable();
for (String muid : remoteTimetable.keySet()) { for (String time : remoteTimetable.get(muid).split(";")) { childSchedule.timetable().put(muid, times);
for (String muid : remoteStatetable.keySet()) { if (remoteStatetable.get(muid).equals("ON")) { childSchedule.statetable().put(muid, ScheduleState.ON);
childSchedule.statetable().put(muid, ScheduleState.OFF);
for (String muid : remoteParamtable.keySet()) { for (String param : remoteParamtable.get(muid).split(";")) { childSchedule.paramstable().put(muid, params);
childs.put(identity, childSchedule);
public void schedule(String muid, long[] delays, String[] params) { if (self.timetable().containsKey(muid)) { self.timetable().get(muid).add(delay);
self.timetable().put(muid, new ArrayList());
self.timetable().get(muid).add(delay);
self.paramstable().put(muid, Arrays.asList(params));
self.statetable().put(muid, ScheduleState.ON);
kernel.handle(new ScheduleUpdatedEvent());
public void unschedule(String muid) throws ModuleNotFoundException { kernel.handle(new ScheduleUpdatedEvent());
public void force(Ice.Identity identity, String muid, String[] params) { kernel.handle(new ScheduleTimeComeEvent(identity, muid, params));
public Map timetable() { Map result = new HashMap();
for (String muid : self.timetable().keySet()) { StringBuilder sb = new StringBuilder();
for (Long time : self.timetable().get(muid)) { result.put(muid, sb.toString());
return result;
public Map statetable() { Map result = new HashMap();
for (String muid : self.statetable().keySet()) { result.put(muid, self.statetable().get(muid).toString());
return result;
public Map paramtable() { Map result = new HashMap();
for (String muid : self.paramstable().keySet()) { StringBuilder sb = new StringBuilder();
for (String param : self.paramstable().get(muid)) { result.put(muid, sb.toString());
return result;
public void toogle(String muid) { ScheduleState state = self.statetable().get(muid);
if (state == ScheduleState.OFF) { self.statetable().put(muid, ScheduleState.ON);
self.statetable().put(muid, ScheduleState.OFF);
kernel.handle(new ScheduleUpdatedEvent());
public void cancel(Ice.Identity identity) { logger.debug("cancel scheduing for " + Identities.toString(identity));
childs.remove(identity);
@Override public synchronized void start() { logger.debug("starting " + name);
@Override public synchronized void stop() { logger.debug("stoping " + name);
for (String muid : timers.keySet()) { timers.get(muid).cancel();
@Override public synchronized boolean started() { public synchronized void restart() { logger.debug("restarting " + name);
public void stateChanged(KernelState currentState) { if (currentState instanceof ActiveState) { public void activate() { loadScheduleConfig();
public void deactivate() { saveScheduleConfig();
private void update() { logger.debug("updating scheduler");
Identities.toString(identity));
ScheduleState.ON) { String[childSchedule.paramstable().get(muid).size()]);
childSchedule.timetable().get(muid)) { ScheduleTimeComeEvent( fprms));
private void loadScheduleConfig() { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
Document dom = db.parse(new File(kernel.properties().getProperty( NodeList modules = root.getElementsByTagName("module");
self.timetable().put(muid, delaysList);
self.paramstable().put(muid, paramsList);
} catch (ParserConfigurationException ex) { } catch (IOException ex) { } catch (SAXException ex) { private void saveScheduleConfig() { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Element root = doc.createElement("modules");
for (String muid: self.timetable().keySet()) { Element module = doc.createElement("module");
if (self.statetable().get(muid) == ScheduleState.ON) { Element schedule = doc.createElement("schedule");
Element params = doc.createElement("params");
for (String value: self.paramstable().get(muid)) { TransformerFactory transfac = TransformerFactory.newInstance();
Transformer trans = transfac.newTransformer();
trans.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
trans.setOutputProperty(OutputKeys.STANDALONE, "no");
trans.setOutputProperty(OutputKeys.INDENT, "yes");
DocumentType dt = doc.getDoctype();
trans.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, pub);
trans.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, dt.getSystemId());
OutputStreamWriter sw = new OutputStreamWriter(new FileOutputStream(new File(kernel.properties().getProperty( StreamResult result = new StreamResult(sw);
DOMSource source = new DOMSource(doc);
trans.transform(source, result);
} catch (ParserConfigurationException ex) { } catch (TransformerConfigurationException ex) { } catch (TransformerException ex) { } catch (FileNotFoundException ex) { /** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.driver;
import org.apache.log4j.Logger;
import com.googlecode.snoopyd.core.Kernel;
import com.googlecode.snoopyd.core.event.ChildSessionRecivedEvent;
import com.googlecode.snoopyd.core.event.ParentSessionSendedEvent;
import com.googlecode.snoopyd.core.state.KernelListener;
import com.googlecode.snoopyd.core.state.KernelState;
import com.googlecode.snoopyd.session.IKernelSessionPrx;
import com.googlecode.snoopyd.session.IKernelSessionPrxHelper;
import com.googlecode.snoopyd.session.IUserSessionPrx;
import com.googlecode.snoopyd.session.IUserSessionPrxHelper;
import com.googlecode.snoopyd.session.KernelSession;
import com.googlecode.snoopyd.session.KernelSessionAdapter;
import com.googlecode.snoopyd.session.UserSession;
import com.googlecode.snoopyd.session.UserSessionAdapter;
public class Sessionier extends AbstractDriver implements Driver, private static Logger logger = Logger.getLogger(Sessionier.class);
public Sessionier(Kernel kernel) { super(Sessionier.class.getSimpleName(), kernel);
public IKernelSessionPrx createKernelSession(Ice.Identity identity, kernel.handle(new ChildSessionRecivedEvent(identity, selfSession));
IKernelSessionPrx remoteSession = IKernelSessionPrxHelper KernelSession(kernel))));
kernel.handle(new ParentSessionSendedEvent(kernel.identity(), remoteSession));
public IUserSessionPrx createUserSession(Ice.Identity identity, //kernel.handle(new ChildSessionRecivedEvent(identity, selfSession));
IUserSessionPrx remoteSession = IUserSessionPrxHelper //kernel.handle(new ChildSessionSendedEvent(identity, remoteSession));
public void stateChanged(KernelState currentState) { /** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.driver;
public interface Startable { public boolean started();
public void restart();
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.session;
import com.googlecode.snoopyd.adapter.ModulerAdapter;
import com.googlecode.snoopyd.adapter.SchedulerAdapter;
import com.googlecode.snoopyd.core.Kernel;
import com.googlecode.snoopyd.driver.IModulerPrx;
import com.googlecode.snoopyd.driver.IModulerPrxHelper;
import com.googlecode.snoopyd.driver.ISchedulerPrx;
import com.googlecode.snoopyd.driver.ISchedulerPrxHelper;
import com.googlecode.snoopyd.driver.Moduler;
import com.googlecode.snoopyd.driver.Scheduler;
public class KernelSession { private Kernel kernel;
public KernelSession(Kernel kernel) { public ISchedulerPrx scheduler() { ISchedulerPrx remoteScheduler = ISchedulerPrxHelper.uncheckedCast(kernel.primary().addWithUUID( public IModulerPrx moduler() { IModulerPrx remoteModuler = IModulerPrxHelper.uncheckedCast(kernel /** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.session;
import Ice.Current;
import com.googlecode.snoopyd.driver.IModulerPrx;
import com.googlecode.snoopyd.driver.ISchedulerPrx;
public class KernelSessionAdapter extends _IKernelSessionDisp { private KernelSession kernelSession;
public KernelSessionAdapter(KernelSession kernelSession) { this.kernelSession = kernelSession;
public void destroy(Current current) { public void refresh(Current current) { public IModulerPrx moduler(Current current) { return kernelSession.moduler();
public ISchedulerPrx scheduler(Current current) { return kernelSession.scheduler();
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.session;
import com.googlecode.snoopyd.adapter.ConfigurerAdapter;
import com.googlecode.snoopyd.adapter.ControllerAdapter;
import com.googlecode.snoopyd.adapter.HosterAdapter;
import com.googlecode.snoopyd.adapter.ModulerAdapter;
import com.googlecode.snoopyd.adapter.SchedulerAdapter;
import com.googlecode.snoopyd.core.Kernel;
import com.googlecode.snoopyd.driver.Configurer;
import com.googlecode.snoopyd.driver.Controller;
import com.googlecode.snoopyd.driver.Hoster;
import com.googlecode.snoopyd.driver.IConfigurerPrx;
import com.googlecode.snoopyd.driver.IConfigurerPrxHelper;
import com.googlecode.snoopyd.driver.IControllerPrx;
import com.googlecode.snoopyd.driver.IControllerPrxHelper;
import com.googlecode.snoopyd.driver.IHosterPrx;
import com.googlecode.snoopyd.driver.IHosterPrxHelper;
import com.googlecode.snoopyd.driver.IModulerPrx;
import com.googlecode.snoopyd.driver.IModulerPrxHelper;
import com.googlecode.snoopyd.driver.ISchedulerPrx;
import com.googlecode.snoopyd.driver.ISchedulerPrxHelper;
import com.googlecode.snoopyd.driver.Moduler;
import com.googlecode.snoopyd.driver.Scheduler;
public class UserSession { private Kernel kernel;
public UserSession(Kernel kernel) { public IHosterPrx hoster() { IHosterPrx remoteHoster = IHosterPrxHelper public IControllerPrx controller() { IControllerPrx remoteController = IControllerPrxHelper.uncheckedCast(kernel.primary().addWithUUID( return remoteController;
public IModulerPrx moduler() { IModulerPrx remoteModuler = IModulerPrxHelper.uncheckedCast(kernel public IConfigurerPrx configurer() { IConfigurerPrx remoteConfigurer = IConfigurerPrxHelper.uncheckedCast(kernel.primary().addWithUUID( return remoteConfigurer;
public ISchedulerPrx scheduler() { ISchedulerPrx remoteScheduler = ISchedulerPrxHelper.uncheckedCast(kernel.primary().addWithUUID( /** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.session;
import com.googlecode.snoopyd.driver.IConfigurerPrx;
import com.googlecode.snoopyd.driver.IControllerPrx;
import com.googlecode.snoopyd.driver.IHosterPrx;
import com.googlecode.snoopyd.driver.IModulerPrx;
import com.googlecode.snoopyd.driver.ISchedulerPrx;
import Ice.Current;
public class UserSessionAdapter extends _IUserSessionDisp { private UserSession userSession;
public UserSessionAdapter(UserSession userSession) { public void destroy(Current current) { public void refresh(Current current) { public IHosterPrx hoster(Current current) { public IControllerPrx controller(Current current) { return userSession.controller();
public IModulerPrx moduler(Current current) { return userSession.moduler();
public IConfigurerPrx configurer(Current current) { return userSession.configurer();
public ISchedulerPrx scheduler(Current current) { return userSession.scheduler();
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.module;
import java.util.UUID;
public abstract class AbstractModule implements Module { protected UUID uudi;
protected String name;
public AbstractModule(UUID uudi, String name) { public UUID uudi() { public String name() { /** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.module;
public interface Module { public Object invoke(Object arg);
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.module;
import java.util.UUID;
public class PythonModule extends AbstractModule implements Module { public PythonModule(UUID uudi, String name) { public Object invoke(Object arg) { // TODO Auto-generated method stub /** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.adapter;
import com.googlecode.snoopyd.driver.Driver;
public interface Adapter { public Driver driver();
public String name();
public Ice.Identity identity();
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.adapter;
import java.util.Map;
import Ice.Current;
import com.googlecode.snoopyd.driver.Configurer;
import com.googlecode.snoopyd.driver._IConfigurerDisp;
public class ConfigurerAdapter extends _IConfigurerDisp { private Configurer configurer;
public ConfigurerAdapter(Configurer configurer) { this.configurer = configurer;
public void reconfigure(Map configuration, Current current) { configurer.reconfigure(configuration);
public Map configuration(Current current) { return configurer.configuration();
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.adapter;
import Ice.Current;
import com.googlecode.snoopyd.driver.Controller;
import com.googlecode.snoopyd.driver._IControllerDisp;
public class ControllerAdapter extends _IControllerDisp { private Controller controller;
public ControllerAdapter(Controller controller) { this.controller = controller;
public void shutdown(Current current) { controller.shutdown();
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.adapter;
import org.apache.log4j.Logger;
import Ice.Current;
import Ice.Identity;
import com.googlecode.snoopyd.driver.Discoverer;
import com.googlecode.snoopyd.driver.Driver;
import com.googlecode.snoopyd.driver._IDiscovererDisp;
public class DiscovererAdapter extends _IDiscovererDisp implements Adapter { private static Logger logger = Logger.getLogger(DiscovererAdapter.class);
private String name;
private Ice.Identity identity;
private Discoverer discoverer;
public DiscovererAdapter(Ice.Identity identity, Discoverer discoverer) { this.discoverer = discoverer;
this.name = DiscovererAdapter.class.getSimpleName();
public void discover(Ice.Identity identity, Current current) { discoverer.discover(identity, current.ctx);
public Driver driver() { public String name() { public Identity identity() { /** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.adapter;
import java.util.Map;
import Ice.Current;
import com.googlecode.snoopyd.driver.Hoster;
import com.googlecode.snoopyd.driver._IHosterDisp;
public class HosterAdapter extends _IHosterDisp { private Hoster hoster;
public HosterAdapter(Hoster hoster) { public Map context(Current current) { return hoster.context();
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.adapter;
import java.util.Map;
import Ice.Current;
import com.googlecode.snoopyd.driver.Moduler;
import com.googlecode.snoopyd.driver._IModulerDisp;
import com.googlecode.snoopymm.ModuleNotFoundException;
public class ModulerAdapter extends _IModulerDisp { private Moduler moduler;
public ModulerAdapter(Moduler moduler) { public Map fetch(Current current) { public void deploy(String muid, String code, Current current) { moduler.deploy(muid, code);
public void undeploy(String muid, Current current) { } catch (ModuleNotFoundException ex) { public String[] launch(String muid, String[] params, Current current) throws com.googlecode.snoopyd.driver.ModuleNotFoundException { return moduler.launch(muid, params);
public void force(String muid, String[] params, Current current) { moduler.force(muid, params);
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.adapter;
import java.util.Map;
import Ice.Current;
import Ice.Identity;
import com.googlecode.snoopyd.driver.ISchedulerPrx;
import com.googlecode.snoopyd.driver.ModuleNotFoundException;
import com.googlecode.snoopyd.driver.Scheduler;
import com.googlecode.snoopyd.driver._ISchedulerDisp;
public class SchedulerAdapter extends _ISchedulerDisp { private Scheduler scheduler;
public SchedulerAdapter(Scheduler scheduler) { public Map timetable(Current current) { return scheduler.timetable();
public Map statetable(Current current) { return scheduler.statetable();
public void schedule(String muid, long[] delays, String[] params, scheduler.schedule(muid, delays, params);
public void unschedule(String muid, Current current) scheduler.unschedule(muid);
public void toogle(String muid, Current current) { public void synchronize(Identity identity, ISchedulerPrx remoteScheduler, scheduler.synchronize(identity, remoteScheduler);
public Map paramtable(Current current) { return scheduler.paramtable();
public void force(Identity identity, String muid, String[] params, scheduler.force(identity, muid, params);
package com.googlecode.snoopyd.adapter;
import org.apache.log4j.Logger;
import Ice.Current;
import Ice.Identity;
import com.googlecode.snoopyd.driver.Driver;
import com.googlecode.snoopyd.driver.Sessionier;
import com.googlecode.snoopyd.driver._ISessionierDisp;
import com.googlecode.snoopyd.session.IKernelSessionPrx;
import com.googlecode.snoopyd.session.IUserSessionPrx;
public class SessionierAdapter extends _ISessionierDisp implements Adapter { private static Logger logger = Logger.getLogger(SessionierAdapter.class);
private Ice.Identity identity;
private Sessionier sessionier;
public SessionierAdapter(Identity identity, Sessionier sessionier) { this.name = SessionierAdapter.class.getSimpleName();
public IKernelSessionPrx createKernelSession(Identity identity, IKernelSessionPrx selfSession, Current current) { return sessionier.createKernelSession(identity, selfSession);
public IUserSessionPrx createUserSession(Identity identity, return sessionier.createUserSession(identity, selfSession);
public Driver driver() { public Identity identity() { /** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.config;
import java.io.Serializable;
public class Configuration implements Serializable { public static class ConfigurationBuilder { public ConfigurationBuilder rate(int rate) { public Configuration build() { public final int rate;
public Configuration(int rate) { /** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.config;
public class ConfigurationManager { public ConfigurationManager() { /** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopyd.util;
import Ice.Identity;
public final class Identities { public static Identity randomIdentity(String domain) { return new Identity(java.util.UUID.randomUUID().toString(), domain);
public static String toString(Identity identity) { return identity.category + "/" + identity.name;
public static Identity clone(Identity identity) { public static Identity stringToIdentity(String identity) { String args[] = identity.split("/");
public static boolean equals(Identity id1, Identity id2) { return id1.name.equals(id2.name) && id1.category.equals(id2.category);
public static Identity xor(Identity id1, Identity id2) { // ex: 154d2630-fafd-4bcb-9cac-dec42ec4ba9c if (!id1.category.equals(id2.category)) { domain");
String id1Part[] = id1.name.split("-");
String id2Part[] = id2.name.split("-");
String resultPart[] = new String[5];
resultPart[0] = Long.toHexString(Long.valueOf(id1Part[0], 16) ^ Long.valueOf(id2Part[0], 16));
while (resultPart[0].length() < 8) { resultPart[0] = "0" + resultPart[0]; } resultPart[1] = Long.toHexString(Long.valueOf(id1Part[1], 16) ^ Long.valueOf(id2Part[1], 16));
while (resultPart[1].length() < 4) { resultPart[1] = "0" + resultPart[1]; } resultPart[2] = Long.toHexString(Long.valueOf(id1Part[2], 16) ^ Long.valueOf(id2Part[2], 16));
while (resultPart[2].length() < 4) { resultPart[2] = "0" + resultPart[2]; } resultPart[3] = Long.toHexString(Long.valueOf(id1Part[3], 16) ^ Long.valueOf(id2Part[3], 16));
while (resultPart[3].length() < 4) { resultPart[3] = "0" + resultPart[3]; } resultPart[4] = Long.toHexString(Long.valueOf(id1Part[4], 16) ^ Long.valueOf(id2Part[4], 16));
while (resultPart[4].length() < 12) { resultPart[4] = "0" + resultPart[4]; } String result = resultPart[0] + "-" + resultPart[1] + "-" + resultPart[2] + "-" + resultPart[3] + "-" + resultPart[4];
return new Identity(result, id1.category);
@echo off rem rem Copyrigth 2011, Snoopy Project rem set CP=lib/snoopyd.jar;lib/log4jjar;lib/Ice.jar;config/log4j.properies;lib/sigar.jar;lib/mysql-connector-javabin.jar;
set DEFINES=-Dsnoopyd.configuration=config/snoopyd.conf Dlog4j.configuration=config/log4j.properties set LIB=native/;
set ENTRY_POINT=com.googlecode.snoopyd.Launcher java -Xms64m -Xmx128m -Xss64m -classpath %CP% -Djava.library.path=%LIB% %DEFINES% %ENTRY_POINT% #!/bin/sh # Copyrigth 2011, Snoopy Project CP=lib/snoopyd.jar;lib/log4j-1.2.15.jar;lib/Ice.jar;config/log4j.properies;lib/sigar.jar;
DEFINES=-Dsnoopyd.configuration=config/snoopyd.conf Dlog4j.configuration=config/log4j.properties LIB=lib/;
ENTRY_POINT=com.googlecode.snoopyd.Launcher java -Xms64m -Xmx128m -Xss64m -classpath $CP -Djava.library.path=$LIB $DEFINES $ENTRY_POINT log4j.rootLogger=DEBUG, FILE, CONSOLE log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.ConversionPattern= %c - %m%n log4j.appender.FILE=org.apache.log4j.RollingFileAppender log4j.appender.FILE.File=log/snoopyd.log log4j.appender.FILE.MaxFileSize=2MB log4j.appender.FILE.MaxBackupIndex= log4j.appender.FILE.layout=org.apache.log4j.PatternLayout log4j.appender.FILE.layout.ConversionPattern= %c - %m%n log4j.logger.com.googlecode.snoopyd.driver.Discoverer=DEBUG log4j.logger.com.googlecode.snoopyd.driver.Aliver=DEBUG log4j.logger.com.googlecode.snoopyd.driver.Networker=DEBUG log4j.logger.com.googlecode.snoopyd.driver.Sessionier=DEBUG Панель управления // ********************************************************************** // Copyright 2011 Snoopy Project // 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. // 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.
// ********************************************************************** #ifndef SNOOPYD_ICE #define SNOOPYD_ICE #include module com { module googlecode { module snoopycp { }; }; };
#endif /** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopycp;
import com.googlecode.snoopycp.core.Snoopycp;
import javax.swing.JOptionPane;
public class Launcher { public static void main(String args[]) { Snoopycp snoopycp = new Snoopycp();
status = snoopycp.main(Defaults.APP_NAME, args, System.getProperty("snoopycp.configuration", Defaults.DEFAULT_CONFIGURATION));
} catch (Ice.FileException ex) { System.out.println(ex.getMessage());
JOptionPane.showMessageDialog(null, e.getMessage());
System.exit(status);
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopycp;
public final class Defaults { public static final String APP_NAME = "snoopycp";
public static final String APP_VER = "0.1";
public static final String DEFAULT_CONFIGURATION = "snoopycp.conf";
public static final String DEFAULT_ADAPTER_NAME = "Adapter";
// path to icons, pics and other staff public static final String PATH_TO_SHARE = "/com/googlecode/snoopycp/share/";
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopycp.core;
import com.googlecode.snoopycp.controller.Coordinator;
import com.googlecode.snoopycp.controller.DomainController;
import com.googlecode.snoopycp.ui.MainFrame;
import org.apache.log4j.Logger;
public class Snoopycp extends Ice.Application { public static Logger logger = Logger.getLogger(Snoopycp.class);
public static final int EXIT_SUCCESS = 0;
public static final int EXIT_FAILURE = 999;
public static class ShutdownHook extends Thread { private Coordinator coordinator;
public ShutdownHook(Coordinator coordinator) { this.coordinator = coordinator;
coordinator.terminate();
@Override public int run(String[] args) { Ice.Communicator communicator = communicator();
Ice.Properties properties = communicator.getProperties();
Domain domain = new Domain(communicator, properties.getProperty("Snoopy.Domain"));
DomainController controller = new DomainController(domain);
MainFrame view = new MainFrame(controller);
Coordinator coordinator = new Coordinator(domain, view);
setInterruptHook(new ShutdownHook(coordinator));
coordinator.launch();
return EXIT_SUCCESS;
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopycp.core;
import com.googlecode.snoopycp.util.Identities;
import java.util.Map;
import org.apache.log4j.Logger;
public class Discoverer { public static Logger logger = Logger.getLogger(Discoverer.class);
private Domain domain;
public Discoverer(Domain domain) { this.domain = domain;
public void discover(Ice.Identity identity, Map context) { logger.debug("discoverer recieved from " + Identities.toString(identity));
domain.cacheit(identity, context);
//System.out.println("OS type: " + context.get("os"));
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopycp.core;
import Ice.Current;
import Ice.Identity;
public class DiscovererAdapter extends _IDiscovererDisp { private Discoverer discoverer;
public DiscovererAdapter(Discoverer discoverer) { this.discoverer = discoverer;
public void discover(Identity identity, Current current) { discoverer.discover(identity, current.ctx);
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopycp.core;
import Ice.Communicator;
import Ice.Identity;
import com.googlecode.snoopycp.Defaults;
import com.googlecode.snoopycp.util.Identities;
import com.googlecode.snoopyd.driver.IConfigurerPrx;
import com.googlecode.snoopyd.driver.IControllerPrx;
import com.googlecode.snoopyd.driver.IHosterPrx;
import com.googlecode.snoopyd.driver.IModulerPrx;
import com.googlecode.snoopyd.driver.ISchedulerPrx;
import com.googlecode.snoopyd.driver.ISessionierPrx;
import com.googlecode.snoopyd.driver.ISessionierPrxHelper;
import com.googlecode.snoopyd.session.IUserSessionPrx;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Observable;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.log4j.Logger;
public class Domain extends Observable implements Runnable { public static Logger logger = Logger.getLogger(Domain.class);
private Ice.Identity identity;
private Ice.Communicator communicator;
private String name;
private Ice.ObjectAdapter adapter;
private Set hosts;
private Map enviroment;
private Map life;
private Map cache;
private Map hosters;
private Map sessions;
private Map controllers;
private Map hashes;
private Map osPull;
private Map modulers;
private Map schedulers;
private Map modulesStatus;
private Map modulesName;
private Map configurers;
public Domain(Communicator communicator, String name) { this.identity = Identities.randomIdentity(name);
this.communicator = communicator;
this.hosts = new HashSet();
this.enviroment = new HashMap();
this.life = new HashMap();
this.cache = new ConcurrentHashMap();
this.sessions = new ConcurrentHashMap();
this.controllers = new ConcurrentHashMap();
this.hosters = new ConcurrentHashMap();
this.osPull = new ConcurrentHashMap();
this.modulers = new ConcurrentHashMap();
this.schedulers = new ConcurrentHashMap();
this.configurers = new ConcurrentHashMap();
this.modulesStatus = new ConcurrentHashMap();
this.modulesName = new ConcurrentHashMap();
this.hashes = new HashMap();
this.adapter = communicator.createObjectAdapter(Defaults.DEFAULT_ADAPTER_NAME);
this.adapter.add(new DiscovererAdapter(new Discoverer(this)), communicator.stringToIdentity(Discoverer.class.getSimpleName()));
this.adapter.activate();
Thread self = new Thread(this);
public String name() { public Ice.Identity identity() { public Ice.Communicator communicator() { return communicator;
public void cacheit(Ice.Identity identity, Map context) { synchronized (this) { cache.put(identity, context);
life.put(identity, System.currentTimeMillis());
hosts.add(context.get("hostname"));
enviroment.put(context.get("hostname"), identity);
osPull.put(identity, context.get("os"));
context.get("primary");
ISessionierPrxHelper.checkedCast(communicator.stringToProxy(proxy));
logger.debug("Checked cast to remote session");
remoteSessionier.createUserSession(identity(), null);
sessions.put(identity, remoteSessionPrx);
IHosterPrx remoteHoster = remoteSessionPrx.hoster();
IControllerPrx remoteController = remoteSessionPrx.controller();
controllers.put(identity, remoteController);
IModulerPrx remoteModuler = remoteSessionPrx.moduler();
modulers.put(identity, remoteModuler);
modulesName.put(identity, remoteModuler.fetch());
ISchedulerPrx remoteScheduler = remoteSessionPrx.scheduler();
schedulers.put(identity, remoteScheduler);
schedulers.get(identity).ice_ping();
modulesStatus.put(identity, schedulers.get(identity).statetable());
IConfigurerPrx remoteConfigurer = remoteSessionPrx.configurer();
configurers.put(identity, remoteConfigurer);
} catch (Ice.ConnectionRefusedException ex) { logger.warn("Problem with fetch information about remote node: " + ex.getMessage());
logger.debug("New host: " + context.get("hostname") + " was added");
logger.debug(newSize + " hosts in domain");
enviroment.get(context.get("hostname")) == null) { enviroment.put(context.get("hostname"), identity);
context.hashCode()) { hashes.put(identity, context.hashCode());
public Set hosts() { public Map osPull() { public boolean isDied(Ice.Identity identity) { return !enviroment.containsValue(identity);
public Map enviroment() { return Collections.unmodifiableMap(enviroment);
public Map cache(Ice.Identity identity) { return cache.get(identity);
public IHosterPrx hoster(Ice.Identity identity) { return hosters.get(identity);
public IModulerPrx moduler(Ice.Identity _identity) { return modulers.get(_identity);
public ISchedulerPrx scheduler(Ice.Identity _identity) { return schedulers.get(_identity);
public IControllerPrx controller(Ice.Identity identity) { return controllers.get(identity);
public IConfigurerPrx configurer(Ice.Identity identity) { return configurers.get(identity);
public Map moduleStatus(Ice.Identity _ident) { return modulesStatus.get(_ident);
public Map moduleName(Ice.Identity _ident) { return modulesName.get(_ident);
public IUserSessionPrx session(Ice.Identity identity) { return sessions.get(identity);
public void updateModules(Ice.Identity _ident) { this.sessions.get(_ident).ice_ping();
this.sessions.get(_ident).moduler().fetch();
this.modulesName.remove(_ident);
this.modulesName.put(_ident, map);
schedulers.get(_ident).ice_ping();
modulesStatus.remove(_ident);
modulesStatus.put(_ident, schedulers.get(_ident).statetable());
logger.debug("Modules list updated");
} catch (Ice.ConnectionRefusedException ex) { logger.warn("Updating modules list failed: " + ex.getMessage());
@Override public void run() { //modulesStatus.clear();
if (System.currentTimeMillis() - life.get(id) > 10000) { from domain");
} catch (InterruptedException ex) { logger.warn("Thread cann`t fall into dream: " + ex.getMessage());
public void notifyObserver() { notifyObservers();
logger.debug("Domain is changed. Observers notified.");
public void removeHost(String _hostname) { this.hosts.remove(_hostname);
logger.debug("Host: " + _hostname + " was removed. " + hosts.size());
notifyObserver();
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopycp.controller;
import com.googlecode.snoopycp.core.Domain;
import com.googlecode.snoopycp.model.GraphModel;
import com.googlecode.snoopycp.model.TableModel;
import com.googlecode.snoopycp.model.TreeModel;
import java.awt.Color;
import java.awt.Paint;
import org.apache.commons.collections15.Transformer;
public class DomainController { private Domain domain;
public DomainController(Domain domain) { this.domain = domain;
public TableModel createTableModel() { return new TableModel(domain);
public TreeModel createTreeModel() { return new TreeModel(domain);
public GraphModel createGraphModel() { return new GraphModel(domain);
public Transformer createLabelTransformer() { return new Transformer() { public String transform(String vertex) { public Transformer createFillTransformer() { return new Transformer() { public Paint transform(String vertex) { if (domain.enviroment().get(vertex) == null) { Ice.Identity identity = domain.enviroment().get(vertex);
String state = domain.cache(identity).get("state");
/** * Copyright 2011 Snoopy Project * 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. * 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 com.googlecode.snoopycp.controller;