001/* 002 * Copyright 2006 - 2013 003 * Stefan Balev <stefan.balev@graphstream-project.org> 004 * Julien Baudry <julien.baudry@graphstream-project.org> 005 * Antoine Dutot <antoine.dutot@graphstream-project.org> 006 * Yoann Pigné <yoann.pigne@graphstream-project.org> 007 * Guilhelm Savin <guilhelm.savin@graphstream-project.org> 008 * 009 * This file is part of GraphStream <http://graphstream-project.org>. 010 * 011 * GraphStream is a library whose purpose is to handle static or dynamic 012 * graph, create them from scratch, file or any source and display them. 013 * 014 * This program is free software distributed under the terms of two licenses, the 015 * CeCILL-C license that fits European law, and the GNU Lesser General Public 016 * License. You can use, modify and/ or redistribute the software under the terms 017 * of the CeCILL-C license as circulated by CEA, CNRS and INRIA at the following 018 * URL <http://www.cecill.info> or under the terms of the GNU LGPL as published by 019 * the Free Software Foundation, either version 3 of the License, or (at your 020 * option) any later version. 021 * 022 * This program is distributed in the hope that it will be useful, but WITHOUT ANY 023 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 024 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 025 * 026 * You should have received a copy of the GNU Lesser General Public License 027 * along with this program. If not, see <http://www.gnu.org/licenses/>. 028 * 029 * The fact that you are presently reading this means that you have had 030 * knowledge of the CeCILL-C and LGPL licenses and that you accept their terms. 031 */ 032package org.graphstream.stream.rmi; 033 034import java.rmi.Naming; 035import java.rmi.RemoteException; 036import java.rmi.server.UnicastRemoteObject; 037import java.util.concurrent.ConcurrentLinkedQueue; 038 039import org.graphstream.stream.AttributeSink; 040import org.graphstream.stream.ElementSink; 041import org.graphstream.stream.Sink; 042import org.graphstream.stream.Source; 043 044public class RMISource extends UnicastRemoteObject implements RMIAdapterIn, 045 Source { 046 private static final long serialVersionUID = 6635146473737922832L; 047 048 ConcurrentLinkedQueue<AttributeSink> attributesListeners; 049 ConcurrentLinkedQueue<ElementSink> elementsListeners; 050 051 public RMISource() throws RemoteException { 052 super(); 053 054 attributesListeners = new ConcurrentLinkedQueue<AttributeSink>(); 055 elementsListeners = new ConcurrentLinkedQueue<ElementSink>(); 056 } 057 058 public RMISource(String name) throws RemoteException { 059 this(); 060 bind(name); 061 } 062 063 public void bind(String name) { 064 try { 065 Naming.rebind(String.format("//localhost/%s", name), this); 066 } catch (Exception e) { 067 e.printStackTrace(); 068 } 069 } 070 071 public void edgeAdded(String graphId, long timeId, String edgeId, 072 String fromNodeId, String toNodeId, boolean directed) 073 throws RemoteException { 074 for (ElementSink gel : elementsListeners) 075 gel.edgeAdded(graphId, timeId, edgeId, fromNodeId, toNodeId, 076 directed); 077 } 078 079 public void edgeAttributeAdded(String graphId, long timeId, String edgeId, 080 String attribute, Object value) throws RemoteException { 081 for (AttributeSink gal : attributesListeners) 082 gal.edgeAttributeAdded(graphId, timeId, edgeId, attribute, value); 083 } 084 085 public void edgeAttributeChanged(String graphId, long timeId, 086 String edgeId, String attribute, Object oldValue, Object newValue) 087 throws RemoteException { 088 for (AttributeSink gal : attributesListeners) 089 gal.edgeAttributeChanged(graphId, timeId, edgeId, attribute, 090 oldValue, newValue); 091 } 092 093 public void edgeAttributeRemoved(String graphId, long timeId, 094 String edgeId, String attribute) throws RemoteException { 095 for (AttributeSink gal : attributesListeners) 096 gal.edgeAttributeRemoved(graphId, timeId, edgeId, attribute); 097 } 098 099 public void edgeRemoved(String graphId, long timeId, String edgeId) 100 throws RemoteException { 101 for (ElementSink gel : elementsListeners) 102 gel.edgeRemoved(graphId, timeId, edgeId); 103 } 104 105 public void graphAttributeAdded(String graphId, long timeId, 106 String attribute, Object value) throws RemoteException { 107 for (AttributeSink gal : attributesListeners) 108 gal.graphAttributeAdded(graphId, timeId, attribute, value); 109 } 110 111 public void graphAttributeChanged(String graphId, long timeId, 112 String attribute, Object oldValue, Object newValue) 113 throws RemoteException { 114 for (AttributeSink gal : attributesListeners) 115 gal.graphAttributeChanged(graphId, timeId, attribute, oldValue, 116 newValue); 117 } 118 119 public void graphAttributeRemoved(String graphId, long timeId, 120 String attribute) throws RemoteException { 121 for (AttributeSink gal : attributesListeners) 122 gal.graphAttributeRemoved(graphId, timeId, attribute); 123 } 124 125 public void graphCleared(String graphId, long timeId) 126 throws RemoteException { 127 for (ElementSink gel : elementsListeners) 128 gel.graphCleared(graphId, timeId); 129 } 130 131 public void nodeAdded(String graphId, long timeId, String nodeId) 132 throws RemoteException { 133 for (ElementSink gel : elementsListeners) 134 gel.nodeAdded(graphId, timeId, nodeId); 135 } 136 137 public void nodeAttributeAdded(String graphId, long timeId, String nodeId, 138 String attribute, Object value) throws RemoteException { 139 for (AttributeSink gal : attributesListeners) 140 gal.nodeAttributeAdded(graphId, timeId, nodeId, attribute, value); 141 } 142 143 public void nodeAttributeChanged(String graphId, long timeId, 144 String nodeId, String attribute, Object oldValue, Object newValue) 145 throws RemoteException { 146 for (AttributeSink gal : attributesListeners) 147 gal.nodeAttributeChanged(graphId, timeId, nodeId, attribute, 148 oldValue, newValue); 149 } 150 151 public void nodeAttributeRemoved(String graphId, long timeId, 152 String nodeId, String attribute) throws RemoteException { 153 for (AttributeSink gal : attributesListeners) 154 gal.nodeAttributeRemoved(graphId, timeId, nodeId, attribute); 155 } 156 157 public void nodeRemoved(String graphId, long timeId, String nodeId) 158 throws RemoteException { 159 for (ElementSink gel : elementsListeners) 160 gel.nodeRemoved(graphId, timeId, nodeId); 161 } 162 163 public void stepBegins(String graphId, long timeId, double step) 164 throws RemoteException { 165 for (ElementSink gel : elementsListeners) 166 gel.stepBegins(graphId, timeId, step); 167 } 168 169 public void addAttributeSink(AttributeSink listener) { 170 attributesListeners.add(listener); 171 } 172 173 public void addElementSink(ElementSink listener) { 174 elementsListeners.add(listener); 175 } 176 177 public void addSink(Sink listener) { 178 attributesListeners.add(listener); 179 elementsListeners.add(listener); 180 } 181 182 public void removeAttributeSink(AttributeSink listener) { 183 attributesListeners.remove(listener); 184 } 185 186 public void removeElementSink(ElementSink listener) { 187 elementsListeners.remove(listener); 188 } 189 190 public void removeSink(Sink listener) { 191 attributesListeners.remove(listener); 192 elementsListeners.remove(listener); 193 } 194 195 public void clearAttributeSinks() { 196 attributesListeners.clear(); 197 elementsListeners.clear(); 198 } 199 200 public void clearElementSinks() { 201 elementsListeners.clear(); 202 } 203 204 public void clearSinks() { 205 attributesListeners.clear(); 206 } 207}