Client/server RMI app using Command pattern: return values and exceptions

I'm developing a client/server java app via RMI. Actually I'm using the cajo framework overtop RMI (any cajo devs/users here?). Anyways, there is a lot of functionality the server needs to expose, all of which is split and encapsulated in manager-type classes that the server has access to. I get the feeling though that bad things will happen to me in my sleep if I just expose instances of the managers, and I really don't like the idea of writing 24682763845 methods that the server needs to individually expose, so instead I'm using the Command pattern (writing 24682763845 individual MyCommand classes is only slightly better). I haven't used the command pattern since school, so maybe I'm missing something, but I'm finding it to be messy. Here's the setup: I've got a public abstract Command which holds information about which user is attempting to execute the command, and when, and lots of public MyCommands extending Command, each with a mandatory execute() method which does the actual dirty work of talking to the model-functionality managers. The server has a command invoker executeCommand(Command cmd) which checks the authenticity of the user prior to executing the command.
What I'm interested in is return values and exceptions. I'm not sure if these things really fit in with a true command pattern in general, but it sure would be nice to have return values and exceptions, even if only for the sake of error detection.
First, return values. I'd like each Command to return a result, even if it's just boolean true if nothing went wrong, so in my Command class I have a private Object result with a protected setter, public getter. The idea is, in the execute() method, after doing what needs to be done, setResult(someResult) is called. The invoker on the server, after running acommand.execute() eventually returns acommand.getResult(), which of course is casted by the client into whatever it should be. I don't see a way to do this using generics though, because I don't see a way to have the invoker's return value as anything other than Object. Suggestions? All this means is, if the client were sending a GetUserCommand cmd I'd have to cast like User user = (User)server.executeCommand(cmd), or sending an AssignWidgetToGroup cmd I'd have to cast like Boolean result = (Boolean)server.executeCommand(cmd). I guess that's not too bad, but can this be done better?
Second, exceptions. I can have the Command's execute() method throw Exception, and the server's invoker method can in turn throw that Exception. Problem is, with a try/catch on the client side, using RMI (or is this just a product of cajo?) ensures that any exception thrown by a remote method will come back as a java.lang.reflect.InvocationTargetException. So for example, if in MyCommand.execute() I throw new MySpecialException, the server's command invoker method will in turn throw the same exception, however the try/catch on the client side will catch InvocationTargetException e. If I do e.getCause().printStackTrace(), THERE be my precious MySpecialException. But how do I catch it? Can it be caught? Nested try/catch won't work, because I can't re-throw the cause of the original exception. For now, instead of throwing exceptions the server is simply returning null if things don't go as planned, meaning on the client side I would do something like if ((result = server.executeCommand(cmd)) == null) { /* deal with it */ } else { /* process result, continue normally */ }.
So using the command pattern, although doing neat things for me like centralizing access to the server via one command-invoking method which avoids exposing a billion others, and making it easy to log who's running what and when, causes me null-checks, casting, and no obvious way of error-catching. I'd be grateful if anyone can share their thoughts/experiences on what I'm trying to do. I'll post some of my code tomorrow to give things more tangible perspective.

First of all, thanks for taking the time to read, I know it's long.
Secondly, pardon me, but I don't see how you've understood that I wasn't going to or didn't want to use exceptions, considering half my post is regarding how I can use exceptions in my situation. My love for exception handling transcends time and space, I assure you, that's why I made this thread.
Also, you've essentially told me "use exceptions", "use exceptions", and "you can't really use exceptions". Having a nested try/catch anytime I want to catch the real exception does indeed sound terribly weak. Just so I'm on the same page though, how can I catch an exception, and throw the cause?
try {
catch (Exception e) {
     Throwable t = e.getCause();
     // now what?
}Actually, nested try/catches everywhere is not happening, which means I'm probably going to ditch cajo unless there's some way to really throw the proper exception. I must say however that cajo has done everything I've needed up until now.
Anyways, what I'd like to know is...what's really The Right Way (tm) of putting together this kind of client/server app? I've been thinking that perhaps RMI is not the way to go, and I'm wondering if I should be looking into more of a cross-language RPC solution. I definitely do want to neatly decouple the client from server, and the command pattern did seem to do that, but maybe it's not the best solution.
Thanks again for your response, ejp, and as always any comments and/or suggestions would be greatly appreciated.

Similar Messages

  • Com.evermind.server.rmi.RMIConnectionException: Unknown command: 0

    hei!
    I have a simple SessionBean, deployed to remote OC4J.(the bean is tested locally and is fine)
    using Jdeveloper, I create a client to call my sessionBean methods.
    If I create the client to run agains the embedded oc4j, it works fine.
    If I create a client that runs agains the remote oc4j, I get this error:
    com.evermind.server.rmi.RMIConnectionException: Unknown command: 0
    and a lot of
    java.lang.Object com.evermind.server.rmi.RemoteInvocationHandler.invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])     
    appreciate your help
    Regards
    RT

    Russel ,
    Have you started remote OC4J Server? Also can you able to browse
    JNDI tree of Remote OC4J Server from JDeveloper?
    Also provide following information in order to understand your problem fully
    1. Which OC4J version you are using?
    2. Platform in which you are testing your application?
    3. Provide full stack trace of error that you are getting
    Cheers
    --Venky                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • I got ma apps on ma iphone via downlding it 4m ma sim...nw when i downloaded apps using itunes in ma laptop and then syncing it....ma existing apps got deleted.....so i jus want to chnge settings so that after syncing it ma before apps dont get delete????

    i got ma apps on ma iphone via downlding it 4m ma sim...nw when i downloaded apps using itunes in ma laptop and then syncing it....ma existing apps got deleted.....so i jus want to chnge settings so that after syncing it ma before apps dont get delete????please help

    Joe91 - Short and sweet, and really helpful - thanks! I wrote a fairly long post to explain the situation. Skip to the last paragraph, and you miss the point.

  • Distributing client/server forms app

    Hi
    I am distributing a client/server forms/reports app that calls stored database procedures.
    Does anyone have information on best-practice for version-control/distribution of upgrades etc? What is a good model to follow? At the moment I am using CVS but it is getting very complicated knowing which client has which version of a form/report/procedure
    All input appreciated
    Jim

    Thanks Damisetty,
    How have you handled when installing in different versions of Windows, i.e. if you prepare the installation on Windows 2000 does it work for installing on Windows XP or the other way around?
    Besides the technical issue, there is the licensing issue, have you used this method for customers that just buy the DB, without forms?
    Could any of the Oracle folks throw some light on the subject?
    Regards.

  • Why struts used Command Pattern?(can not understand)

    I can not understand Commnad Pattern,
    Can anyone explain it with struts?
    thanks sincere!

    Encapsulating set of actions in to a single method call is nothing but command.
    In case of struts.. U must be having an request handler classes, which are defined in ur XML file.
    Once a request comes to a servlet, it reads the value of the action attribute. Depending on the value of the action attribute, appropriate request handler class will be instantiated.
    This request handler class encapsulates all the action through a single method call. This particular scenario, we can compare with command pattern
    class MyCommand extends AbstractCommand
    public Response execute()
    // add the code for action to be performed to fulfill the request
    client call will be
    AbstarctCommand ac = xxx.createInstance(action)
    Response resp = ac.execute();
    This one sample for command pattern

  • How to use command pattern in grid computing

    IS there a more comprehensive command pattern example available ? In a real life command method, execute method will query coherence cache for objects. Does this cause any kind of deadlock issue, i.e., in cases where Command being a coherence cluster managed object, which in turn would query another coherence managed object from another cluster member.

    You might want to look at the Processing Pattern which is a more generalized and richer model for
    doing distributed processing.
    Check out this video: http://www.youtube.com/watch?v=Ic2ib_VIqWQ
    Edited by: rhanckel on Oct 29, 2010 7:33 AM

  • How to stop SQL Server Agent Job if Stored Procedure returns value 0

    I have SQL Server 2012 SSIS.
    I have 2 SSIS packages.
    I have created SQL Server Agent Job for running packages.
    I have created steps. If first step have run succesfully next step is run.
    I have need to add new logic.
    I have validation stored procedure, which validate DB table values and returns 1 or 0.
    I would like to create logic where first of all this SP is runned. Return value of SP determines if steps are run or not.
    I was thinking to use Execute SQL Task for running SP.
    If value 1 is returned, then run rest of Tasks is run.
    If value 0 is returned, what should I do so that Job is stopped? I need assistance! 
    I want current step to stop never moved to next step.
    Is there any SSIS tasks, which can stop the Job?
    Or should I make Step for running validation SP?
    How to do so that if value 0 is returned stop Job.
    Kenny_I

    Please refer the below link:
    http://technet.microsoft.com/en-us/library/aa260308(v=sql.80).aspx
    Please read Remarks carefully!!!
    Remarks
    If a job is currently executing a step of type CmdExec, the process being run (for example, MyProgram.exe) is forced to end prematurely. Premature ending can result in unpredictable behavior such as files in use by the process being held open. Consequently,
    sp_stop_job should be used only in extreme circumstances if the job contains steps of type CmdExec.
    Permissions
    Execute permissions default to the public role in the
    msdb database. A user who can execute this procedure and is a member of the
    sysadmin fixed role can stop any job. A user who is not a member of the
    sysadmin role can use sp_stop_job to stop only the jobs he/she owns.
    When sp_stop_job is invoked by a user who is a member of the
    sysadmin fixed server role, sp_stop_job will be executed under the security context in which the SQL Server service is running. When the user is not a member of the
    sysadmin group, sp_stop_job will impersonate the SQL Server Agent proxy account, which is specified using
    xp_sqlagent_proxy_account. If the proxy account is not available,
    sp_stop_job will fail. This is only true for Microsoft® Windows® NT 4.0 and Windows 2000. On Windows 9.x, there is no impersonation and
    sp_stop_job is always executed under the security context of the Windows 9.x user who started SQL Server.

  • I set up "Find My Iphone App" using the same apple id and password on two iphones. Now the app only finds the phone that I did the setup on first. Do I need a different apple id and password on each phone for the app to run correctly?

    I setup two iphones on "Find My Iphone App" Using the same apple id on each phone. Now the app finds only the phone I setup first. Do I need to use two different apple ids? If your answer is yes then how do I errase the setup in the second phone and assign a new id?

    As TJBUSMC1973 states, and as I said earlier, the Find My iPhone app has nothing to do with your use of Find My iPhone. The app is just used if necessary to locate another iOS device from that particular iOS device. To see if both of your devices are being located in Find My iPhone, log into www.icloud.com and select Find My iPhone. Both of the devices should appear. If they do not, then go into whichever of the devices does not appear and make sure that Find My iPhone is activated. It has to be activated through iCloud, and for both to show on the same map, they both have to have the same iCloud ID.

  • Create SP that returns value and at the same time displays query result in output window

    I would like create an SP which will return the records from the table and also return value to my c# client application.
    For Example:
    Select * from employee returns all the query results in output window.
    Now I want to create an SP
    Create procedure Test
    As
    Declare @ret int,
    Select * from employee
    set @ret = Select count(*) from employee
    if @ret > 0
    return 1
    else
    return 0
    The above algo should return 1 0r 0 to c# client application and at the same time display all employees in sql query output window.
    Can u pls help in this regard.

    The above algo should return 1 0r 0 to c# client application and at the same time display all employees in sql query output window.
    Why?  and No!
    Why?  Your procedure generates a resultset of some number of rows.  You check the resultset for the presence of rows to determine if "anything is there".  You don't need a separate value to tell you this.  Note that it helps
    to post tsql that is syntactically correct.   While we're at it, if you just need to know that rows exist there is no need to count them since that does more work than required.  Simply test for existence using the appropriately-named function
    "exists".  E.g., if exists (select * from dbo.employee). 
    No!  A stored procedure does not display anything anywhere.  The application which executes the procedures is responsible for the consumption of the resultset; it chooses what to do and what to display. 
    Lastly, do not get into the lazy habit of using the asterisk in your tsql code.  That is not best practice.  Along with that, you should also get into the following best practice habits:
    schema-qualify your objects (i.e., dbo.employee)
    terminate every statement - it will eventually be required.

  • List Managers Displays Return Value and Not Display Value

    Hi
    I have created a List Manager (based on a Popup LOV). My lov is as follows:
    SELECT pt.paper_code d, pt.paper_icode r
    FROM uo_sturec.paper_table pt
    WHERE pt.start_year <= 2006
    AND (pt.finish_year >= 2006 OR pt.finish_year = 0)
    AND pt.paper_type = 60
    ORDER BY pt.paper_code
    However, when I select something from the popup, it displays the pt.paper_icode in the field and when I click on Add, the pt.paper_icode is added to the selction box.
    What can I do to make the display value, pt.paper_code appear both in the field and the selection box?
    Kind regards
    Jo

    Hi Scott
    Thank you for your reply. However, I want the return value to be pt.paper_icode, because I'll be using this value to populate another item on the same page. Is there some javascript I could write to just change the display value of the List Manager while preserving its return value?
    Thanks.
    Jo

  • Multi-select lists, their return values and showing their display value

    I have a multi select list which is dynamic. The display and return values are pulled from a table where the return value is the Primary Key.
    When people select a few options, the value is stored in session state as 11:12:13 (etc...). From here, I run these numbers through a process which takes a report ID and the multi-select string, and saves individual rows as Report_id, individual multi select value until there are no more multi select values.
    This is great, they're tied in as a foreign key to the LOV lookup table, and they are easily search able.
    I have trouble where I want to list a report's entire multi-select list. I have a function combine the numbers with a : in between them and RTRIM the last one, so I have an identical string to what a multi-select table uses. 11:12:13 (etc..)
    When I assign it to display as an LOV in a report, it just shows the 11:12:13 instead of listing out the values.
    Single number entries, where someone only selected one option in a multi select, display fine.
    Am I doing this wrong?

    Scott - you're right on the money. I did this initially because I thought assigning an LOV display value to a report column would yield the results I wanted.
    I want to do this without referring to the original table... meaning I don't want a function to have to go out and get the names, I'd like my LOV assignment to do it. This saves headache of having to change something in 2 places if it ever changed.
    Am I not going to be able to do this?
    I created a test multi-LOV page, it doesn't work with original(not processed in my function) LOV assignments either, unless you only select one.

  • Handling the return values and passing values to a dialog

    Dear all,
    I am trying to return values from a dialog to a page.
    I am following a tutorial:
    http://www.oracle.com/technology/products/jdev/101/howtos/adfdialog/index.html
    its okey, but I couldnt understand the following code:
    public void handleReturn(ReturnEvent event)
    if (event.getReturnValue() != null)
    Customer cst;
    String name;
    String psw;
    cst = (Customer)event.getReturnValue();
    CustomerList.getCustomers().add(cst);
    name = cst.getFirstName();
    psw = cst.getPassword();
    inputText1.setSubmittedValue(null);
    inputText1.setValue(name);
    inputText2.setSubmittedValue(null);
    inputText2.setValue(psw);
    please help me what are these variables?
    that I could be able to map with me own.
    Regards:
    Muhammad Nadeem
    [email protected]

    If you look further down on the tutorial, you will notice that these values are set in the dialog done() and cancel() actionListeners. Similarly, you will return your own object(s) when calling returnFromProcess() - see the done() method.
    Regards,
    Nick

  • Where we use Conversions like Fixed Value and Value mapping?

    where we use Conversions? like Fixed Value and Value mapping?

    Mostly say when u have a scenario like converting a value in the source to a another in
    target. Say in source it might me KM but in target u might need Kilometers and u hav multiple entries like this.
    Ref:
    http://help.sap.com/saphelp_nw04/helpdata/en/13/ba20dd7beb14438bc7b04b5b6ca300/frameset.htm
    https://www.sdn.sap.com/irj/sdn/xi-elearning

  • [solved] use command's return

    hi to all
    how can i use the return of a command executed in a terminal ?
    thanks
    Last edited by nTia89 (2010-12-30 14:32:34)

    Allan wrote:In what language?
    bash
    sisco311 wrote:http://mywiki.wooledge.org/BashGuide/Te … nditionals
    thanks very much is what i was searching !
    Last edited by nTia89 (2010-12-30 14:17:22)

  • SQL Server 2014 installation using command line fails to remove the extraction folder when complete

    We need to install SQL Server 2014 Express in /QS mode (shows
    progress through the UI, but does not accept any input or show any error messages) as
    my setup-Prerequisite. I passed my installation parameters to
    SQLEXPRWT_x64_ENU.exe, when I ran my application it pop-ups
    user to select the folder to extract files. After I choose the folder, SQL
    files got extracted and the installation proceeded and it got succeed.
    But it fails to remove the extraction folder when installation is complete.

    There is an issue that /qs parameter is not recognized and cannot be used the same
    way as in SQL 2012. That issue will be addressed in SQL Server 2014 Service Pack 1.
    https://connect.microsoft.com/SQLServer/feedback/details/878374/sql-server-2014-express-qs-parameter-requires-user-input

Maybe you are looking for