[Remoterengine-commits] r87 - in pkg/RemoteREngine/src/src: client/org/rosuda/REngine/remote/client common/org/rosuda/REngine/remote/common common/org/rosuda/REngine/remote/common/callbacks common/org/rosuda/REngine/remote/common/console server/org/rosuda/REngine/remote/server server/org/rosuda/REngine/remote/server/callbacks server/org/rosuda/REngine/remote/server/console
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Aug 27 18:00:40 CEST 2009
Author: romain
Date: 2009-08-27 18:00:40 +0200 (Thu, 27 Aug 2009)
New Revision: 87
Added:
pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/callbacks/InputCallback.java
pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/callbacks/RestrictedCallback.java
pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/console/Command.java
pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/console/CommandSender.java
pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/console/RemoteREngineClientSender.java
pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/console/UnknownSender.java
pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/console/Command.java
pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/console/ServerConsoleSender.java
Modified:
pkg/RemoteREngine/src/src/client/org/rosuda/REngine/remote/client/RemoteREngine.java
pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/RemoteREngineInterface.java
pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/callbacks/RCallback.java
pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/RemoteREngine_Server.java
pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/RemoteRMainLoopCallbacks.java
pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/callbacks/CallbackSender.java
pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/callbacks/ClientCallbackListener.java
pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/console/ConsoleCallbackHandler.java
pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/console/ConsoleSync.java
pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/console/ConsoleThread.java
Log:
add callback to inform clients about input command from another client
Modified: pkg/RemoteREngine/src/src/client/org/rosuda/REngine/remote/client/RemoteREngine.java
===================================================================
--- pkg/RemoteREngine/src/src/client/org/rosuda/REngine/remote/client/RemoteREngine.java 2009-08-27 13:37:41 UTC (rev 86)
+++ pkg/RemoteREngine/src/src/client/org/rosuda/REngine/remote/client/RemoteREngine.java 2009-08-27 16:00:40 UTC (rev 87)
@@ -125,6 +125,7 @@
/* System.out.println( "subscribe to the server" ) ; */
UnicastRemoteObject.exportObject(this) ;
JRIEngineGlobalVariables variables = engine.subscribe(this) ;
+ callbackDispatcher = new ClientCallbackDispatcher(this) ;
callbackDispatcher.start();
serverHashCode = variables.hashCode ;
globalEnv = variables.globalEnv ;
@@ -503,5 +504,17 @@
}
}
+ /**
+ * Send a command to the console
+ * @param command command to send
+ */
+ public void sendToConsole( String command ){
+ try {
+ engine.sendToConsole(command, this ) ;
+ } catch (RemoteException e) {
+ /* what now */
+ }
+ }
+
}
Modified: pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/RemoteREngineInterface.java
===================================================================
--- pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/RemoteREngineInterface.java 2009-08-27 13:37:41 UTC (rev 86)
+++ pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/RemoteREngineInterface.java 2009-08-27 16:00:40 UTC (rev 87)
@@ -192,7 +192,7 @@
* @param cmd command to send to the REPL
* @throws RemoteException
*/
- public void sendToConsole( String cmd ) throws RemoteException ;
+ public void sendToConsole( String cmd, RemoteREngineClient client ) throws RemoteException ;
}
Added: pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/callbacks/InputCallback.java
===================================================================
--- pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/callbacks/InputCallback.java (rev 0)
+++ pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/callbacks/InputCallback.java 2009-08-27 16:00:40 UTC (rev 87)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2009, Romain Francois <francoisromain at free.fr>
+ *
+ * This file is part of the RemoteREngine project
+ *
+ * The RemoteREngine project is free software:
+ * you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * The RemoteREngine project is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the RemoteREngine project. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.rosuda.REngine.remote.common.callbacks;
+
+import org.rosuda.REngine.remote.common.console.CommandSender;
+
+/**
+ * Callback sent when another client has sent a command
+ *
+ * @author Romain Francois
+ *
+ */
+public class InputCallback extends RestrictedCallback {
+
+ private static final long serialVersionUID = 1L;
+
+ protected String command ;
+
+ protected transient CommandSender sender;
+
+ public InputCallback( String command, CommandSender sender){
+ this.command = command;
+ this.sender = sender;
+ }
+
+ public String getCommand(){
+ return command;
+ }
+
+ public CommandSender getSender(){
+ return sender;
+ }
+
+}
Modified: pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/callbacks/RCallback.java
===================================================================
--- pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/callbacks/RCallback.java 2009-08-27 13:37:41 UTC (rev 86)
+++ pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/callbacks/RCallback.java 2009-08-27 16:00:40 UTC (rev 87)
@@ -60,4 +60,13 @@
*/
public abstract boolean needsResponse() ;
+ /**
+ * Is this callback restricted to a subset of clients
+ *
+ * @return true if the callback is restricted
+ */
+ public boolean isRestricted(){
+ return false;
+ }
+
}
Added: pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/callbacks/RestrictedCallback.java
===================================================================
--- pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/callbacks/RestrictedCallback.java (rev 0)
+++ pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/callbacks/RestrictedCallback.java 2009-08-27 16:00:40 UTC (rev 87)
@@ -0,0 +1,11 @@
+package org.rosuda.REngine.remote.common.callbacks;
+
+public class RestrictedCallback extends RCallbackNoResponse {
+
+ private static final long serialVersionUID = 1L;
+
+ public final boolean isRestricted(){
+ return true;
+ }
+
+}
Added: pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/console/Command.java
===================================================================
--- pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/console/Command.java (rev 0)
+++ pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/console/Command.java 2009-08-27 16:00:40 UTC (rev 87)
@@ -0,0 +1,29 @@
+package org.rosuda.REngine.remote.common.console;
+
+import java.io.Serializable;
+
+public class Command implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ protected String command;
+
+ protected CommandSender sender ;
+
+ public Command( String command){
+ this( command, new UnknownSender() ) ;
+ }
+
+ public Command( String command, CommandSender sender){
+ this.command = command ;
+ this.sender = sender;
+ }
+
+ public String getCommand( ){
+ return command;
+ }
+
+ public CommandSender getSender(){
+ return sender;
+ }
+}
Added: pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/console/CommandSender.java
===================================================================
--- pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/console/CommandSender.java (rev 0)
+++ pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/console/CommandSender.java 2009-08-27 16:00:40 UTC (rev 87)
@@ -0,0 +1,5 @@
+package org.rosuda.REngine.remote.common.console;
+
+public abstract class CommandSender {
+
+}
Added: pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/console/RemoteREngineClientSender.java
===================================================================
--- pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/console/RemoteREngineClientSender.java (rev 0)
+++ pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/console/RemoteREngineClientSender.java 2009-08-27 16:00:40 UTC (rev 87)
@@ -0,0 +1,16 @@
+package org.rosuda.REngine.remote.common.console;
+
+import org.rosuda.REngine.remote.common.RemoteREngineClient;
+
+public class RemoteREngineClientSender extends CommandSender {
+
+ protected RemoteREngineClient client ;
+
+ public RemoteREngineClientSender(RemoteREngineClient client){
+ this.client = client ;
+ }
+
+ public RemoteREngineClient getClient(){
+ return client;
+ }
+}
Added: pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/console/UnknownSender.java
===================================================================
--- pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/console/UnknownSender.java (rev 0)
+++ pkg/RemoteREngine/src/src/common/org/rosuda/REngine/remote/common/console/UnknownSender.java 2009-08-27 16:00:40 UTC (rev 87)
@@ -0,0 +1,8 @@
+package org.rosuda.REngine.remote.common.console;
+
+public class UnknownSender extends CommandSender {
+
+ public UnknownSender(){
+
+ }
+}
Modified: pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/RemoteREngine_Server.java
===================================================================
--- pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/RemoteREngine_Server.java 2009-08-27 13:37:41 UTC (rev 86)
+++ pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/RemoteREngine_Server.java 2009-08-27 16:00:40 UTC (rev 87)
@@ -42,7 +42,11 @@
import org.rosuda.REngine.remote.common.callbacks.CallbackResponse;
import org.rosuda.REngine.remote.common.callbacks.RCallback;
import org.rosuda.REngine.remote.common.callbacks.RCallbackWithResponse;
+import org.rosuda.REngine.remote.common.callbacks.ReadConsoleCallback;
import org.rosuda.REngine.remote.common.callbacks.ServerDownCallback;
+import org.rosuda.REngine.remote.common.console.Command;
+import org.rosuda.REngine.remote.common.console.CommandSender;
+import org.rosuda.REngine.remote.common.console.RemoteREngineClientSender;
import org.rosuda.REngine.remote.common.exceptions.AlreadyRegisteredException;
import org.rosuda.REngine.remote.common.exceptions.FileAlreadyExistsException;
import org.rosuda.REngine.remote.common.exceptions.NotRegisteredException;
@@ -394,11 +398,14 @@
/**
* Called when a client wants to send a command to the REPL
+ *
* @param cmd command to send to the REPL
+ * @param client the client that sent the command
+ *
* @throws RemoteException
*/
- public void sendToConsole( String cmd ){
- consoleSync.add( cmd ) ;
+ public void sendToConsole( String cmd, RemoteREngineClient origin ){
+ consoleSync.add( new Command( cmd, new RemoteREngineClientSender(origin) ) );
}
private void debug( String message){
@@ -467,6 +474,12 @@
public void sendCallbackToListeners(RCallback callback){
callbackSender.addToQueue( callback ) ;
}
+
+ public void sendCallbackToOtherListeners(ReadConsoleCallback callback,
+ CommandSender sender) {
+
+ }
+
/**
* start the console thread
@@ -500,6 +513,6 @@
public synchronized Vector<CallbackListener> getCallbackListeners() {
return callbackListeners ;
}
-
+
}
Modified: pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/RemoteRMainLoopCallbacks.java
===================================================================
--- pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/RemoteRMainLoopCallbacks.java 2009-08-27 13:37:41 UTC (rev 86)
+++ pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/RemoteRMainLoopCallbacks.java 2009-08-27 16:00:40 UTC (rev 87)
@@ -26,12 +26,14 @@
import org.rosuda.REngine.remote.common.callbacks.CancelCallback;
import org.rosuda.REngine.remote.common.callbacks.ChooseFileCallback;
import org.rosuda.REngine.remote.common.callbacks.ChooseFileCallbackResponse;
+import org.rosuda.REngine.remote.common.callbacks.InputCallback;
import org.rosuda.REngine.remote.common.callbacks.RBusyCallback;
import org.rosuda.REngine.remote.common.callbacks.RCallbackWithResponse;
import org.rosuda.REngine.remote.common.callbacks.RFlushConsoleCallback;
import org.rosuda.REngine.remote.common.callbacks.RShowMessageCallback;
import org.rosuda.REngine.remote.common.callbacks.RWriteConsoleCallback;
import org.rosuda.REngine.remote.common.callbacks.ReadConsoleCallback;
+import org.rosuda.REngine.remote.common.console.Command;
import org.rosuda.REngine.remote.server.callbacks.CallbackResponseWaiter;
/**
@@ -163,11 +165,15 @@
server.sendCallbackToListeners( callback ) ;
/* wait for the next available command: this blocks */
- String result = server.getConsoleSync().next() ;
+ Command cmd = server.getConsoleSync().next() ;
+ String result = cmd.getCommand() ;
+
+ InputCallback input = new InputCallback( result, cmd.getSender() ) ;
+ server.sendCallbackToListeners( input ) ;
+
if( !result.endsWith( "\n" ) ){
result += "\n" ;
}
-
return result ;
}
Modified: pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/callbacks/CallbackSender.java
===================================================================
--- pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/callbacks/CallbackSender.java 2009-08-27 13:37:41 UTC (rev 86)
+++ pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/callbacks/CallbackSender.java 2009-08-27 16:00:40 UTC (rev 87)
@@ -19,10 +19,17 @@
*/
package org.rosuda.REngine.remote.server.callbacks;
+import org.rosuda.REngine.remote.common.RemoteREngineClient;
import org.rosuda.REngine.remote.common.callbacks.CallbackListener;
+import org.rosuda.REngine.remote.common.callbacks.InputCallback;
import org.rosuda.REngine.remote.common.callbacks.RCallback;
+import org.rosuda.REngine.remote.common.console.CommandSender;
+import org.rosuda.REngine.remote.common.console.RemoteREngineClientSender;
+import org.rosuda.REngine.remote.common.console.UnknownSender;
import org.rosuda.REngine.remote.common.tools.StoppableThreadWithSynchronizer;
import org.rosuda.REngine.remote.server.RemoteREngine_Server;
+import org.rosuda.REngine.remote.server.console.ConsoleCallbackHandler;
+import org.rosuda.REngine.remote.server.console.ServerConsoleSender;
/**
* Thread that sends callbacks to callback listeners
@@ -45,9 +52,49 @@
*/
@Override
public void dealWith(RCallback callback) {
+
+ /* FIXME: need to review this and add some filtering mechanism into the callback classes */
+
+ if( callback instanceof InputCallback ){
+ InputCallback input = (InputCallback)callback ;
+ CommandSender sender = input.getSender() ;
+
+ /* it comes from a client */
+ if( sender instanceof RemoteREngineClientSender ){
+
+ RemoteREngineClientSender origin = (RemoteREngineClientSender)sender ;
+ for( CallbackListener listener: server.getCallbackListeners() ){
+ if( listener instanceof ClientCallbackListener ){
+ /* find if the listener and the sender are working with the same client */
+ RemoteREngineClient lis_client = ( (ClientCallbackListener)listener ).getClient() ;
+ if( origin.getClient().equals( lis_client ) ){
+ continue ;
+ }
+ }
+ listener.handleCallback( callback ) ;
+ }
+ } else if( sender instanceof UnknownSender){
+ sendToAll( callback );
+ } else if( sender instanceof ServerConsoleSender ){
+
+ /* send to all except the console handler */
+ for( CallbackListener listener: server.getCallbackListeners() ){
+ if( ! (listener instanceof ConsoleCallbackHandler) ){
+ listener.handleCallback( callback ) ;
+ }
+ }
+ }
+ } else{
+ sendToAll( callback );
+ }
+ }
+
+ private void sendToAll( RCallback callback ){
+ /* send to all */
for( CallbackListener listener: server.getCallbackListeners() ){
listener.handleCallback( callback ) ;
}
}
+
}
Modified: pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/callbacks/ClientCallbackListener.java
===================================================================
--- pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/callbacks/ClientCallbackListener.java 2009-08-27 13:37:41 UTC (rev 86)
+++ pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/callbacks/ClientCallbackListener.java 2009-08-27 16:00:40 UTC (rev 87)
@@ -74,4 +74,11 @@
return map.remove(client) ;
}
+ /**
+ * @return The client associated with this listener
+ */
+ public RemoteREngineClient getClient(){
+ return client;
+ }
+
}
Added: pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/console/Command.java
===================================================================
Modified: pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/console/ConsoleCallbackHandler.java
===================================================================
--- pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/console/ConsoleCallbackHandler.java 2009-08-27 13:37:41 UTC (rev 86)
+++ pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/console/ConsoleCallbackHandler.java 2009-08-27 16:00:40 UTC (rev 87)
@@ -20,6 +20,7 @@
package org.rosuda.REngine.remote.server.console;
import org.rosuda.REngine.remote.common.callbacks.CallbackListener;
+import org.rosuda.REngine.remote.common.callbacks.InputCallback;
import org.rosuda.REngine.remote.common.callbacks.RCallback;
import org.rosuda.REngine.remote.common.callbacks.RShowMessageCallback;
import org.rosuda.REngine.remote.common.callbacks.RWriteConsoleCallback;
@@ -49,13 +50,16 @@
* - handle it
*/
public void dealWith(RCallback callback){
+
if( callback instanceof RWriteConsoleCallback ){
System.out.print( ((RWriteConsoleCallback)callback).getMessage() ) ;
} else if( callback instanceof RShowMessageCallback ){
System.out.print( ((RShowMessageCallback)callback).getMessage() ) ;
} else if( callback instanceof ReadConsoleCallback ){
System.out.print( ((ReadConsoleCallback)callback).getPrompt() ) ;
- }
+ } else if( callback instanceof InputCallback ){
+ System.out.print( ((InputCallback)callback).getCommand() + "\n") ;
+ }
/* else if( callback instanceof ReadConsoleCallback ){
System.out.print( "\nEnter file name: " ) ;
} */
Modified: pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/console/ConsoleSync.java
===================================================================
--- pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/console/ConsoleSync.java 2009-08-27 13:37:41 UTC (rev 86)
+++ pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/console/ConsoleSync.java 2009-08-27 16:00:40 UTC (rev 87)
@@ -19,6 +19,7 @@
*/
package org.rosuda.REngine.remote.server.console;
+import org.rosuda.REngine.remote.common.console.Command;
import org.rosuda.REngine.remote.common.tools.Synchronizer;
import org.rosuda.REngine.remote.server.RemoteREngine_Server;
@@ -28,7 +29,7 @@
* @author Romain Francois
*
*/
-public class ConsoleSync extends Synchronizer<String> {
+public class ConsoleSync extends Synchronizer<Command> {
/**
* associated server
Modified: pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/console/ConsoleThread.java
===================================================================
--- pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/console/ConsoleThread.java 2009-08-27 13:37:41 UTC (rev 86)
+++ pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/console/ConsoleThread.java 2009-08-27 16:00:40 UTC (rev 87)
@@ -19,6 +19,7 @@
*/
package org.rosuda.REngine.remote.server.console;
+import org.rosuda.REngine.remote.common.console.Command;
import org.rosuda.REngine.remote.common.console.ConsoleReadLine;
import org.rosuda.REngine.remote.common.tools.ServiceException;
import org.rosuda.REngine.remote.common.tools.ServiceManager;
@@ -66,7 +67,8 @@
requestStop();
server.shutdown() ; /* let clients know */
} else {
- server.getConsoleSync().add( line ) ;
+ Command command = new Command( line, new ServerConsoleSender(this) ) ;
+ server.getConsoleSync().add( command ) ;
}
}
Added: pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/console/ServerConsoleSender.java
===================================================================
--- pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/console/ServerConsoleSender.java (rev 0)
+++ pkg/RemoteREngine/src/src/server/org/rosuda/REngine/remote/server/console/ServerConsoleSender.java 2009-08-27 16:00:40 UTC (rev 87)
@@ -0,0 +1,14 @@
+package org.rosuda.REngine.remote.server.console;
+
+import org.rosuda.REngine.remote.common.console.CommandSender;
+
+public class ServerConsoleSender extends CommandSender {
+
+ protected ConsoleThread console;
+ public ServerConsoleSender(ConsoleThread console){
+ this.console = console;
+ }
+ public ConsoleThread getConsoleThread(){
+ return console;
+ }
+}
More information about the Remoterengine-commits
mailing list