Command Pattern Issue

Hello.
I started learning about command pattern and so I tried taking the data I learned and applying it to what I have been doing. I put together an image gallery using command pattern but the images are not appearing on the stage and I can't figure out why. There are no errors a trace I put in is showing up.
Been going over all my files for a while now and I have not been able to figure out what I have done wrong. : (
Is someone out there who is familiar with this - possibly you! - that would be willing to look at my structure and maybe you could spot what I am doing wrong?
I would post the code here but the structure contains 9 files (most of which are very small) and I dont know which file to post.
Thanks for any help!
http://www.ziddu.com/download/9026721/commandpatternforpost.zip.html

Hi Maruthee.
The simple answer is that Contexts remain in the cluster after Commands have been executed. They are not removed.
Hope this helps.
-- Brian
Brian Oliver | Architect | Oracle Coherence Engineering
Oracle Fusion Middleware

Similar Messages

  • Resolution required for an issue found in Coherence Command pattern in a production system

    We have a Trade and position processing system. Command pattern is used as it's core mechanism to distribute and execute these Trade and position commands acros the Coherence Cluster. So far the design pattern has worked very well for us.
    However, a scenario was encountered in our productions system, which disallowed to execute commands on a command node.
    Attached is a document which contains a complete detailed analysis of the cause. The end conclusion was that currently command pattern is not able to manage the context state correctly, when there are cluster failures.

    Hi Sandeep,
    If you've not done so already, please raise an issue in the issue tracking system for the project: https://java.net/projects/cohinc/
    Alternatively, raise a Coherence Service Request (SR) and it will be forwarded to us with the appropriate information.
    -- Brian
    Brian Oliver | Architect | Oracle Coherence

  • Feedback on use of incubator command pattern

    Hi,
    We are currently prototyping some different solutions using coherence incubator (namely command pattern) and are looking for some feedback as to the viability and potential improvements to the solution.
    h3. Summary of Prototype
    The prototype does the following (i have a nice sequence diagram for this but don't see a way to attach it :():
    + client (e.g. through coherence extend) calls local api to save a "message" for a particular account (e.g. Account id = 1234). This calls namedcache.put and inserts an entry into the cache.
    + BackingMapListener is configured for the cache into which the client indirectly inserts. In the prototype this is a spring bean that extends AbstractMultiplexingBackingMapListener - which is fully "loaded" with all the required dependencies for the processing of the message (services, etc.).
    + The listener then registers a new context (using ContextManager) using a "grouping" id based on the sequence/ordering requirements. For example, say that each message against an account needs to be processed in order. The context would get instantiated with name = "1234", so that subsequent requests for account 1234 will get queued against the context with the same name whilst the previous request(s) are still processing. Messages for other accounts would register a different context name so they will get simultaneously processed.
    NB: The functionality of this listener can be paralleled to the sample in CommandPatternExample for one submission. I am not entirely clear where command submissions typically "tie-in" but I am planning to kick them off from a backingmaplistener. I briefly explored using the 'com.oracle.coherence.common.events.dispatching.listeners.DelegatingBackingMapListener' to dispatch the commands but not entirely how this would tie in. As I understand it the delegating backingmaplistener is used within the 'liveobjects' context and dispatches entries that implement the LifecycleAwareEntry but not sure how we would create "custom-contexts" as we require (i.e. the identifier is not for the key of the cache entry but rather a subset of that -e.g. account id versus account message id).
    + A command is then created to process the account message, which is comprised of
    - the Account which needs processed (the value of the backing map listener contains the Account itself)
    - Any components that are required during processing (services, daos, etc - service might itself be injected with daos, etc.)
    + The newly instantiated command is then then submitted to the CommandSubmitter for the appropriate contextIdentifer (the one returned by 1234 in our example).
    From some basic tests, the prototype is behaving as I desire - i.e. it queues and "synchronizes" the commands for the same context and also simultaneously processes commands assigned to different contexts asynchronously. That's great.
    However, there are a number of things I am exploring for the actual implementation. I believe most of these are typical concerns so I wonder if Oracle or anyone can provide some feedback from past experience/proposed recommendations:
    h3. Questions
    h4. 1. Grid/server-side Business Logic Deployment
    One of the things that has occurred to us is that ideally we would like to store the business processing logic (i.e. the heart of the processing within the command) either inside the grid or within a coherence node (i.e. made available through the classpath of the node startup).
    In our case we have a few different "processing models", but ideally the processor/command will simply determine the appropriate control flow (i.e. within the command - or maybe the appropriate lifecycle if we end up using that) and associated business logic off the attributes of the object to be processed. I am not sure if our use case is typical, but to be clear we have a fair bit of business logic to be performed within the 'command', each in separate modules. In implementation, most modules will be interacting with the grid for lookups, etc. but ideally that will be abstracted from the Processor/Command which will only know that it is using an 'accountService' - for e.g.
    Currently the business logic is "loaded" into the listener and "passed on" to the command through composition. Ideally we ant the command would be light-weight and the various "processing models" would either:
    a) be deployed to each node and somehow "available" to the command during execution. Would need to work out how this would be come available to the execution environment; perhaps each 'Context' would wrap the processing details. However, even this is a bit too granular as likely a processing model will apply to many contexts.
    b) Perhaps the business logic/processing components are deployed to the cache itself. Then within the command attributes on the object would be consulted to determine which processing model to "apply" and a simple lookup could return the appropriate control flow/processor(s).
    c) Perhpaps the different logic/flow is embedded in a different "lifecycle" for the event processing and the appropriate lifecycle is detected by the listener and appropirately applied. Even with such a model we'd still like the various processing for each phase to be maintained in the server if possible.
    Has anyone else done something like this and/or are there any thoughts about deploying the business logic to the grid this way? I see advantages/disadvantages with the different solutions, and some of them seem better for upgrades. For example if you upgrade the processing logic whilst requests are still coming in (clearly you would attempt to avoid this) and it is embedded into each node, what would happen if one node has been upgraded and a request comes to that node. Say one of the business logic modules performs a query against the cache which needs to consult another node (e.g. assuming you're using partitioned data) and that node has not received the upgrade and there's a conflict. In that regard perhaps deploying the different processing logic to a replicated cache makes more sense because once updated it should get pushed immediately to all nodes?
    Are these known concerns? I'm new to grid-side processing concepts so just correct me if there's an obvious issue with tis.
    h4. 2. Cleanup/Management of contexts
    One thing I noticed on my prototype is that the context's that I create don't really go away. We are envisioning creating Many context per day (let's just say a few hundred million to be safe)
    so ...
    a) how do people normally remove the contexts? Does the command framework sort this out behind the scenes? I can see the 'stop' method on the CommandExecutor removing the context, but from a quick follow-through the only scenario which seems to potentially call this is if the context version number has changed. Is there some way to change the version when we submit additional commands to the same context?
    b) Is there an issue with creating this many Contexts? As per earlier mention, to reduce overhead ideally the context will not be too heavy but any thoughts on our intended usage? We could use something like a hashing scheme to "bucket" the requests to contexts to reduce the total number of Contexts if required but this is not ideal.
    h4. 3. Creation of new Command Every time.
    In our scenario, each command needs to act upon a given object (e.g. one account). As I see it, this requires us to create a new Command for each message, because I do not see a way to 'pass in' the object to the execute method. Setting it to the context does not work either because we need to queue a few requests to each given context; I played with wrapping the object with GenericContext and setting the value but in reality we're submitting the commands whilst others are currently being processed so I don't see how this could work.
    Any thoughts on this? Do you agree we'll have to create a new command for every message to be processed? We'll likely have millions of Commands per day so this will make a difference for us (although if we eliminate the logic from q#1 or the dependencies are singletons it's not a big deal)
    h4. 4. Concurrency guarantees with the commandpattern
    I also want to confirm my understanding of concurrency controls around the command pattern. Unlike an entry processor which controls updates to the entry upon which it was invoked, the command pattern only guarantees concurrency against processing occuring within the context of the currently operating command. Commands submitted to the same context will be processed synchronously but any entries which may have had a listener which spawned the command submission are in no way guarded. This latter point is pretty obvious I believe since there's no real link but I just want to make sure my assumptions are correct.
    NB: in the scenario I am describing we do NOT need to update the original cache entry into which the account message was submitted. Instead other caches will be updated with results from additional processing logic so this is not that much of an issue for us.
    h4. 5. Confirmation of concerns with "straight" entry processor
    If we were to use a "straight" entry processor (versus command pattern which uses entry processor) which gets kicked off from a threadpool on a backing map listener (for example on insert or update), is it true that if a node were to go down, we would have issues with failover? NB: The reason we would kick off the entry processor from a threadpool would be to "simulate" asynchronous processing. As I see it, if we kicked off a thread on the listener and returned back to the client, nothing would "re-submit" the request if a node goes down. Is that correct?
    ALTERNATIVELY, As I understand it, with an entry processor invoked from a client, it is the client coherence jar that receives the exception when a node goes down mid-process and the coherence jar takes care of "re-sending" the request to another node. So - if the threadpool is managed by the client and the client kicks off an invoke in one of the threads - then I believe the client WILL re-submit the entry processor requests if the node goes down - through the coherence jar/extend - not sure on the details but my point is that the client application does not have to provide any code for the "failover" but the coherence client jar performs this.
    h4. 6. Lifecycle
    I have not explored the "lifecycle" functionality available within the incubator - but as I understand it the main thing it could offer is that if we have many phases of the processing (as we do in most our use cases) - that the processing can be managed with the different lifecycles. NB: To be clear I am referring to 'live objects' with their own series of processing steps - not 100% if Lifecycle directly relates to 'live objects'. If a node goes down and is in the midst of processing 200,000 commands - the entire processing doesn't need to start over.. each request will need to go back to the previous completed phase of the lifecycle but may well avoid duplicated processing. All processing will need to be idempotent regardless, but lifecycles could avoid re-processing that was already complete.
    Is this correct?
    Other benefits?
    (e.g. configurable processing logic as alluded to in Q#1).
    Thanks very much
    Edited by: 822486 on 21-Dec-2010 16:23
    Edited by: 822486 on 21-Dec-2010 16:59

    Hi User 822486,
    When delving into a detailed prototype like the one you have below it's often useful to understand the use cases and business requirements before jumping into a solution. I think it may be best for you to reach out to the Coherence organization within oracle to further discuss these questions in detail so we can better guide you in the different ways to solve problems with Coherence and the incubator. I'll do my best to comment on your prototype and address the questions that you currently have:
    NB: The functionality of this listener can be paralleled to the sample in CommandPatternExample for one submission. I am not entirely clear where command submissions typically "tie-in" but I am planning to kick them off from a backingmaplistener. I briefly explored using the 'com.oracle.coherence.common.events.dispatching.listeners.DelegatingBackingMapListener' to dispatch the commands but not entirely how this would tie in. As I understand it the delegating backingmaplistener is used within the 'liveobjects' context and dispatches entries that implement the LifecycleAwareEntry but not sure how we would create "custom-contexts" as we require (i.e. the identifier is not for the key of the cache entry but rather a subset of that -e.g. account id versus account message id).
    Command submissions are just that, submissions to the command pattern for execution and they can be triggered from anywhere since they run asynchronously. The DelegatingBackingMapListener and the associated eventing model provides you with the foundations for building an Event Driven Architecture on top of coherence. It's used by both the Push Replication Pattern as well as the Messaging Pattern which you could use as references if you wanted to go down the path of using the eventing model as well. It really comes down to your use case (which I don't have a lot of details on at the moment). An Entry that is a LifecycleAwareEntry can basically take action when it's state is changed (an event occurs). As a completely bogus example you could have a AccountMessageDispatcher object in a cache with a DelegatingBackingMapListener configured and you could submit EntryProcessors to this dispatcher that gives it a set of messages to perform for a set of accounts. The Dispatcher could then every time it's updated submit commands for execution. In essence it's formalizing an approach to responding to events on entries - or server side event driven programming.
    h2. Grid/server-side business logic deployment
    Have you looked at the processing pattern at all? It's a framework for building compute grids on top of Coherence and may have more plumbing in place for you to achieve what you're looking for. I think it may be best for us to discuss your use case in more detail to understand the pros and cons of each approach before commenting further on a solution for you.
    h2. Cleanup and Management of contexts
    Contexts are marker interfaces so they can be incredibly lightweight which should allow you to create as many of them as you need. The biggest concern is ensuring that you have enough processing power in your grid to handle the volume of work you want to manage. This should be a simple matter of figuring out your load and sizing your cluster appropriately. The initial design of the command pattern was to have a set of well established contexts that would be used repeatedly. Given that the Command Pattern is primarily an example, you could extend the DefaultContextsManager to have an unregisterContext method.
    h2. Creation of new command every time
    I'm a little confused by your requirement here. Are you saying that you have a set of pre-defined operations that you want to apply to an account for example incrementAccountBalancyBy1? If so, I don't understand why you couldn't submit the same command instance to a context multiple times. While I wouldn't recommend using statics you could have a CommandFactory that returned the same command each time you call getCommand once it was instantiated once. Usually however we expect that you'll have some additional data unique to each message that the command must execute. This could be handled by having a setter on your command for these properties.
    h2. Concurrency Guarantees
    The Command Pattern Guaranteees that for a given context commands are processed synchronously in the order they are received. If you have multiple submitters sending commands to the same context, then the order of when the commands are processed will be based on the order in which they arrive at the node where the Context resides. A context is the control point that gives commands their ordering.
    h2. Confirmation of concerns with "straight" entry processor
    I'm not sure if I follow your question here. EntryProcessors are guaranteed to execute, even in the failure scenario (this is why they're backed up and why they must be idempotent). If you're referring to processing events based on a backing map listener rather than submitting commands, it handles your processing then it's a matter of wether you're asynchronously processing the events or not. If you are synchronously processing things and your node dies while the BML is executing you're right a node failure at that point will result in "nothing happening" and the client will re-try. If however you're asynchronously handling the events from your BML, then you could lose state. This is why we use entries the way we do in the common event layer, we persist state on an entry that we can't lose when a node fails. This allows us to asynchronously process the data after the node has been updated.
    h2. Lifecycle
    With respect to lifecycle if you're referring to LifeCycleAwareEntry - this is a way of designating that an Entry in the cache can process events when modified/mutated. This may be better discussed by phone or in person.

  • 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

  • Coherence 12 Command Pattern Not Working

    We are migrating to the latest version of the Coherence 12. We are using Command Pattern in our code. Followin is the error I am getting
    com.oracle.coherence.common.finitestatemachines.annotation.OnEnterState(value=STARTING) is not compatible with the required methid signature 'Instruction methid(State,State,Context<State>)
    Can you please suggest what can be wrong?
    Also is there any place where I can download the latest incubator jars directly?
    Regards,
    Ashish

    Added a Jira ticket for the same COHINC-94 issue can be tracked over there so closing the thread.
    Ashish Garg

  • Parsing commands from a command line, command-pattern?

    I'd like to create a command line where user type their commands and the application will invoke the appropriate action. There could be many commands with different arguments.
    example:
    FDA G 1033052
    XXLD TA 93843234 G 928322
    etc
    each command has different arguments and each command should perform a db task (it's long).
    Also, the commands can be undo (eg, if user clicks UNDO it will undo the last command)
    for this I realized I need to build the command pattern (hold a stack of all commands) but I'm still debating with some issues:
    1. What parser should I build in order to execute the command
    2. How should I encapsulate the commands in a way that will be easier to invoke, should I add all commands in the beginning to a map where the first argument will be the key and the value will be the class?
    Thank you
    Edited by: xianwinwin on Oct 29, 2009 2:22 AM

    xianwinwin wrote:
    I'd like to create a command line where user type their commands and the application will invoke the appropriate action. There could be many commands with different arguments.
    example:
    FDA G 1033052
    XXLD TA 93843234 G 928322
    Commands like that are going to be error prone for human users.
    etc
    each command has different arguments and each command should perform a db task (it's long).
    Also, the commands can be undo (eg, if user clicks UNDO it will undo the last command)
    for this I realized I need to build the command pattern (hold a stack of all commands) but I'm still debating with some issues:
    1. What parser should I build in order to execute the commandFor the posted examples the parser is trivial - break on space. Validation might be harder.
    2. How should I encapsulate the commands in a way that will be easier to invoke, should I add all commands in the beginning to a map where the first argument will be the key and the value will be the class? You are creating a language. How you interpret the language depends on the definition of the language and specifics of the implementation.
    You could certainly do it as you suggest but there are many other variations as well.

  • Using ExtensibleEnvironment and Command Pattern with 3.7.1 Release

    I am trying to port my project 3.6 project to 3.7.1. I am using the Extensible environment from the jar coherence-3.6-common-1.7.3.20019.jar
    While starting the cluster I am getting the below errors.
    Is there a confguration showing how to configure the Command Pattern and Extensible environment with XSD validation in 3.7.1?
    Exception in thread "main" (Wrapped: Failed to load the factory) (Wrapped: Missi
    ng or inaccessible constructor "com.oracle.coherence.environment.extensible.Exte
    nsibleEnvironment(String)"
    <configurable-cache-factory-config>
    <class-name>com.oracle.coherence.environment.extensible.ExtensibleEnvironment<
    /class-name>
    <init-params>
    <init-param>
    <param-type>java.lang.String</param-type>
    <param-value>C:/work/development/workspace/java/Coherence-Rest/cfg/cache-s
    erver-config.xml</param-value>
    </init-param>
    </init-params>
    </configurable-cache-factory-config>) java.lang.reflect.InvocationTargetExceptio
    n
    at com.tangosol.util.Base.ensureRuntimeException(Base.java:288)
    at com.tangosol.net.ScopedCacheFactoryBuilder.getDefaultFactory(ScopedCa
    cheFactoryBuilder.java:311)
    at com.tangosol.net.DefaultCacheFactoryBuilder.getSingletonFactory(Defau
    ltCacheFactoryBuilder.java:48)
    at com.tangosol.net.DefaultCacheFactoryBuilder.getFactory(DefaultCacheFa
    ctoryBuilder.java:121)
    at com.tangosol.net.ScopedCacheFactoryBuilder.getConfigurableCacheFactor
    y(ScopedCacheFactoryBuilder.java:112)
    at com.tangosol.net.CacheFactory.getConfigurableCacheFactory(CacheFactor
    y.java:126)
    at com.tangosol.net.DefaultCacheServer.getDefaultConfigurableCacheFactor
    y(DefaultCacheServer.java:364)
    at com.tangosol.net.DefaultCacheServer.main(DefaultCacheServer.java:197)
    Caused by: (Wrapped: Missing or inaccessible constructor "com.oracle.coherence.e
    nvironment.extensible.ExtensibleEnvironment(String)"
    <configurable-cache-factory-config>
    <class-name>com.oracle.coherence.environment.extensible.ExtensibleEnvironment<
    /class-name>
    <init-params>
    <init-param>
    <param-type>java.lang.String</param-type>
    <param-value>C:/work/development/workspace/java/Coherence-Rest/cfg/cache-s
    erver-config.xml</param-value>
    </init-param>
    </init-params>
    </configurable-cache-factory-config>) java.lang.reflect.InvocationTargetExceptio
    n
    at com.tangosol.util.Base.ensureRuntimeException(Base.java:288)
    at com.tangosol.run.xml.XmlHelper.createInstance(XmlHelper.java:2652)
    at com.tangosol.run.xml.XmlHelper.createInstance(XmlHelper.java:2536)
    at com.tangosol.net.ScopedCacheFactoryBuilder.getDefaultFactory(ScopedCa
    cheFactoryBuilder.java:273)
    ... 6 more
    Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct
    orAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
    onstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at com.tangosol.util.ClassHelper.newInstance(ClassHelper.java:694)
    at com.tangosol.run.xml.XmlHelper.createInstance(XmlHelper.java:2611)
    ... 8 more
    Caused by: java.lang.RuntimeException: Can't create a NamespaceContentHandler as
    the URI scheme [http] in [http://www.w3.org/2001/XMLSchema-instance] is not sup
    ported
    at com.oracle.coherence.environment.extensible.DefaultConfigurationConte
    xt$Scope.establishNamespaceContentHandlerFor(DefaultConfigurationContext.java:62
    5)
    at com.oracle.coherence.environment.extensible.DefaultConfigurationConte
    xt.ensureNamespaceContentHandler(DefaultConfigurationContext.java:94)
    at com.oracle.coherence.environment.extensible.DefaultConfigurationConte
    xt.processElement(DefaultConfigurationContext.java:254)
    at com.oracle.coherence.environment.extensible.DefaultConfigurationConte
    xt.processDocument(DefaultConfigurationContext.java:204)
    at com.oracle.coherence.environment.extensible.ExtensibleEnvironment.set
    Config(ExtensibleEnvironment.java:438)
    at com.tangosol.net.DefaultConfigurableCacheFactory.<init>(DefaultConfig
    urableCacheFactory.java:193)
    at com.tangosol.net.DefaultConfigurableCacheFactory.<init>(DefaultConfig
    urableCacheFactory.java:179)
    at com.tangosol.net.DefaultConfigurableCacheFactory.<init>(DefaultConfig
    urableCacheFactory.java:155)
    at com.oracle.coherence.environment.extensible.ExtensibleEnvironment.<in
    it>(ExtensibleEnvironment.java:154)
    ... 14 more

    Hi
    Is there a reason you are using the 3.6 version of the incubator with Coherence 3.7 and not the latest INC-10 version? I suspect the 3.6 Incubator does not support normal XML schemas.
    JK

  • Question regarding Command pattern

    Hi!
    I have a question regarding the Command pattern:
    //Invoker as defined in GOF Design Patterns
    public class SomeServer {
        //Receiver as defined in GOF Design Patterns.
        private Receiver receiver;
        //Request from a network client.
        public void service(SomeRequest request) {
            Command cmd = CommandFactory.createCommand(request);
            cmd.execute();
    }The concrete command which implements the Command needs a reference to Receiver in order to execute it's operation but how is the concrete command best configured? Should I send Receiver along with the request
    as a parameter to the createCommand method or should i configure the receiver inside the CommandFactory or
    send it as a paramter to the execute method? Since SomeServer acts as both client and invoker, SomeServer "knows" about the Commands receiver. Is this a bad
    thing?
    Regards
    /Fredrik

    #!/bin/bash
    DATE=$(date '+%y-%m-%d')
    if find | grep -q $DATE ; then
    echo "OK - Backup files found"
    exit 0
    else
    echo "Critical - No Backups found today!"
    exit 2
    fi
    should work too and it's a bit shorter.
    Please remember to mark the thread as solved.

  • Implement command pattern in any way or anything similar or anything at all

    I have a controller class that listens to button presses from my button panel, and it also listens to mouse actions from another drawing panel.
    When I press a button, it indicates some kind of drawing is going to happen in the drawing area. Only one action could be "active" at the same time. (To exemplify, put out square, put out circle, or whatever).
    First I thought of using something similar to the command pattern. But when I press the button (here I wanted to create the command since then I know which one) I dont know yet which coordinates that are of interest. That would mean I would have to pass that data into the command�s execute() method, or create the command first now (right before it should execute)
    Any suggestions of what could be a nice approach here are very welcome.
    I know I am in that phase that I want to "patternize" a bit to much, but hey, at least you learn something and eventually you learn when not/how to use it more properly.

    Maybe you could have a method that would return when the command needed to be excuted.
    I dont get you fully there.
    or could pass something else to the command that it could use determine when it needed to be executed?
    I will however try to also send a bool which indicates whether it comes from a click or not. If that succeeds, I have managed to get all the commands to know by themselves when to do or not to do their stuff.
    The only things that feels bad about that, is that only one command (for the moment at least) makes use of it. But I get rid of the bad smell ;-)
    Add: Turned out that after all changes, most of the commands needed this variable too. Now everything feels good again ;)
    Message was edited by:
    sandsater
    Message was edited by:
    sandsater

  • 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.

  • How to implement command pattern into BC4J framework?

    How to implement command pattern into BC4J framework, Is BC4J just only suport AIDU(insert,update,delete,query) function? Could it support execute function like salary caculation in HR system or posting in GL(general ledger) system? May I create a java object named salaryCalc which use view objects to get the salary by employee and then write it to database?
    Thanks.

    BC4J makes it easy to support the command pattern, right out of the box.
    You can write a custom method on your application module class, then visit the application module wizard and see the "Client Methods" tab to select which custom methods should be exposed for invocation as task-specific commands by clients.
    BC4J is not only for Insert,Update,Delete style applications. It is a complete application framework that automates most of the typical things you need to do while building J2EE applications. You can have a read of my Simplifying J2EE and EJB Development Using BC4J whitepaper to read up on an overview of all the basic J2EE design patterns that the framework implements for you.
    Let us know if you have more specific questions on how to put the framework into practice.

  • Command pattern in processEvent?

    hello
    I wonder if it is possible(anyone already done this?) to use a command pattern in processEvent function as it is widely used in actionPerformed method in conventional java applications.
    In recent jsf code samples in processEvent method I could only find "if ... then " conditions I mean if we have an webapplication consisting of a few pages it's ok but what if I have 100 pages in my webapp? I guess one would not use 100 "if .. then"..
    Is there already a nice solution , pattern to that?
    thanks

    by command pattern.. well.. I don't mean an Execute() function but a kind of getTargetPage() method so that instead of:
    if (facesEvent instanceof FormEvent) {
         FormEvent formEvent = (FormEvent) facesEvent;
         if (formEvent.getCommandName().equals("submit1")) {
         treeId = "/hello1.jsp";
         if (formEvent.getCommandName().equals("submit2")) {
         treeId = "/hello2.jsp";
    I could write just one line:
    if (facesEvent instanceof FormEvent) {
    treeId = ((Command)facesEvent).getTargetPage();
    Does it make sense?

  • Tidal Scheduler Command line issue

    I am unable to pass command parameters with quotes (I need quotes also to be stored in command parameters). The SACmd.exe is not displaying any quotes when Command parameters are passed. I need quotes because I am calling FTP script in Command and source and destination in command parameters. Example is below:
    Command : frppro.exe
    Command parameters should be:  -s "Shared Path!Source" -d "C:\program files\".
    But i am unable to get quotes in command string. Is this a command line issue or let me know is there anyway to get quotes too from command line.

    Try the "fix" I documented at
    http://blog.configmgrftw.com/two-osd-application-install-issues/
    Jason | http://blog.configmgrftw.com

  • WLSE SQL1032N No start database manager command was issued

    Hello,
    i have a problem with my WLSE device.
    it seens like db2 database fails to start.
    2004@WLSE:diag all
    DIAG: IMAGE
    *** PASS: Software image verification passed. ***
    DIAG: BIOS
    *** Drive model does not require BIOS patch. ***
    DIAG: DMA
    Checking disk for DMA errors *** PASS: NO DMA IO errors found. ***
    Checking disk sectors for errors ...*** PASS: NO disk sector errors found. ***
    DIAG: DB2CLEAN *** PASS: No dump files found. ***
    DIAG: DB2VERIFY *** FAIL: Cannot connect to DB2. Integrity verification failed. ***
    DIAG: SERIALNO *** Serial Number -???????? ***
    2004@WLSE:service status
    Process= TFTP
    State = Program started - No mgt msgs received
    Info = Application started by administrator request.
    Process= WirelessSvcMgr
    State = Program started - No mgt msgs received
    Info = Application started by administrator request.
    Process= WLSEjobvm
    State = Running but busy flag set
    Info = WLSEjobvm started.
    Process= WLSEFaults
    State = Running normally
    Info = WLSEFaults is ready.
    Process= CDPbrdcast
    State = Program started - No mgt msgs received
    Info = Application started by administrator request.
    Process= WLSEIdleServer
    State = Program started - No mgt msgs received
    Info = Application started by administrator request.
    Process= WLSERepository
    State = Program started - No mgt msgs received
    Info = Application started by administrator request.
    Process= HaMibDaemon
    State = Program started - No mgt msgs received
    Info = Application started by administrator request.
    Process= WebServer
    State = Program started - No mgt msgs received
    Info = Application started by administrator request.
    Process= Tomcat
    State = Program started - No mgt msgs received
    Info = Application started by administrator request.
    Process= ExcepReporter
    State = Program started - No mgt msgs received
    Info = Application started by administrator request.
    Process= PerfMon
    State = Program started - No mgt msgs received
    Info = Application started by administrator request.
    snmpd (pid 1854) is running...
    Database test failed
    FAIL Version and product query result was:
    SQL1032N No start database manager command was issued. SQLSTATE=57019
    Any idea??? is it possible to start the database manager without restoring the database?
    Thank you in advanced.

    This happens when the database of WLSE is corrupted. Use " reinitdb " command to reinitialize the database. Then try to stop the service for 5 mins and start again.

  • EJB Command Pattern

    How is Command Pattern is light weight as compared to session fascade design pattern???

    Hey Msyal look at http://www.theserverside.com/resources/patterns_review.jsp. You can dowloade the book. Hope that can help you :-)

Maybe you are looking for

  • Help on how to read the content of an XML file from the payload

    I have a receiver channel / mail adapter, that sends e-mails with a XML attachment. I’m trying to write a Bean, that should make it possible to rename the attached XML file dynamically. In the Bean I want to read the content of the attached XML file,

  • How to get message answer in the code

    Hi, I'm using jdeveloper 11.1.2.3.0 I have such a code on save button of my form: public void onSaveClick(ActionEvent actionEvent) { //first code if(...) {     RichPopup.PopupHints hints = new RichPopup.PopupHints();     getOnSavePopup().show(hints);

  • Need exit in PR

    Hi all, I want to know if there any user exit available in PO, which has to trigger when I Move Pur Req to market trolley in Po. Pls help me with ur suggestions. Thank you, Priya

  • Oo4o Runtime-Error 429

    We are successfully using oo4o (8.0.6) to get data from ORACLE Release 7.3 into Word (Office 97 and Office XP). The clients are using NT 4.0 or Windows XP. We tried to install the application on a Windows 2003 terminal server with citrix. We use the

  • Question about MP3 players in Ital

    Hello!I'm an italian boy!I have some problems with my micro zen mp3, there are italian people in this forum?i'm not speak english very well!!help me help me thanksMessage Edited by Catherina-CL on 06-20-2006 09:48 AM