Multiple dispatch

Hi. I understand how multiple dispatch works when you want to base the method called on the type of the parameter. However, I don't understand what you need to do if you'd like to base it off the type of two parameters.
For example, I have a class Hierarchy like the following:
public abstract class A
    String Text;
public class B extends A
    //I've ommitted some things for brevity.  It's just important that B is a subclass of A
public calss C extends A
    int intValue;
public class D extends A
    //What i'd like is to somehow be able to do the following:
    apply( B, C )
        //some stuff
    apply( B, B )
        //some other stuff
    //this could go on
}Can someone point me in the right direction? I've looked at the Visitor pattern and a few sites about multiple dispatch, but I can't figure out how to apply that to this particular situation.

If you have control over the types A-D, then you can either use double dispatch, which can require N^2 methods, or use your own method selection by a tag value. Tag values are sometimes faster, and don't necessarily require the class hierarchy is closed. Another advantage of tags is that you can do more intelligent dispatch, as you might for arithmetic type coercion.
External dispatch means don't have to pollute the classes with double dispatch methods, and makes it easier to do have more than one doubly dispatched method in a hierarchy:
// internal, class A and B extend Base
class A extends Base {
  int foo (Base arg1) { return b.accept_foo(this); }
  int bar (Base arg1) { return b.accept_bar(this); }
  int accept_foo (A arg1) { // foo A,A }
  int accept_foo (B arg1) { // foo A,B }
  int accept_bar (A arg1) { // foo A,A }
  int accept_bar (B arg1) { // foo A,B }
// class B is symmetric
// external
class A extends Base {
  public <T> accept (Selector<T> selector) { return selector.apply(this); }
interface Selector<T> {
  T apply(A arg) ;
  T apply(B arg);
abstract class AbstractFunctor2<T> implements Selector<Selector<T>> {
  // code similar to double selectors below, second selector calls abstract functions
class Foo extends AbstractFunctor2<Integer> {
  public Integer apply (A arg0, B arg1) { ... }
}Either technique can be curried for multiple dispatch.
Where performance is not critical, or you cannot modify the classes, you can use the instanceof operator. That doesn't prevent other users extending the types, but if there's no meaningful default operation for A, you get a runtime error.
External double dispatch and typeTag example:
package dispatch;
abstract class Base {
  static interface Selector <T> {
    T apply (A a);
    T apply (B b);
    T apply (C c);
  static interface Functor1 <T>  {
    T apply (Base arg0);
  static interface Functor2 <T>  {
    T apply (Base arg0, Base arg1);
  public abstract <T> T accept (Selector<T> selector) ;
  Base (int typeTag) { this.typeTag = typeTag; }
  final int typeTag;
class A extends Base {
  A (String value) {
    super(0xA);
    this.value = value;
  final String value;
  public <T> T accept (Selector<T> selector) { return selector.apply(this); }
class B extends Base {
  B (double value) {
    super(0xB);
    this.value = value;
  final double value;
  public <T> T accept (Selector<T> selector) { return selector.apply(this); }
class C extends Base {
  C (int value) {
    super(0xC);
    this.value = value;
  int value;
  public <T> T accept (Selector<T> selector) { return selector.apply(this); }
// external double dispatch using selector
// can keep going for treble, quadruple, with increasing cost of dispatch.
class DoubleDispatchSelector1 implements Base.Selector<Base.Selector<String>>, Base.Functor2<String> {
  public String apply (Base any0, Base any1) {
    return any1.accept(any0.accept(this));
  public Base.Selector<String> apply (final A arg0) {
    return new Base.Selector<String> () {
      public String apply (A arg1) {
        return "AA";// "DoubleDispatchSelector received A(" + arg0.value + ") A(" + arg1.value + ")";
      public String apply (B arg1) {
        return "AB"; // "DoubleDispatchSelector received A(" + arg0.value + ") B(" + arg1.value + ")";
      public String apply (C arg1) {
        return "AC"; // "DoubleDispatchSelector received A(" + arg0.value + ") C(" + arg1.value + ")";
  public Base.Selector<String> apply (final B arg0){
    return new Base.Selector<String> () {
      public String apply (A arg1) {
        return "BA"; // "DoubleDispatchSelector received B(" + arg0.value + ") A(" + arg1.value + ")";
      public String apply (B arg1) {
        return "BB"; // "DoubleDispatchSelector received B(" + arg0.value + ") B(" + arg1.value + ")";
      public String apply (C arg1) {
        return "BC"; // "DoubleDispatchSelector received B(" + arg0.value + ") C(" + arg1.value + ")";
  public Base.Selector<String> apply (final C arg0){
    return new Base.Selector<String> () {
      public String apply (A arg1) {
        return "CA"; // "DoubleDispatchSelector received C(" + arg0.value + ") A(" + arg1.value + ")";
      public String apply (B arg1) {
        return "CB"; // "DoubleDispatchSelector received C(" + arg0.value + ") B(" + arg1.value + ")";
      public String apply (C arg1) {
        return "CC"; // "DoubleDispatchSelector received C(" + arg0.value + ") C(" + arg1.value + ")";
// external double dispatch using selectors, second selectors cached for single threaded use
class DoubleDispatchSelector2 implements Base.Selector<Base.Selector<String>>, Base.Functor2<String> {
  public String apply (Base any0, Base any1) {
    return any1.accept(any0.accept(this));
  public Base.Selector<String> apply (A arg0) {
    selectorA.arg0 = arg0;
    return selectorA;
  public Base.Selector<String> apply (B arg0) {
    selectorB.arg0 = arg0;
    return selectorB;
  public Base.Selector<String> apply (C arg0) {
    selectorC.arg0 = arg0;
    return selectorC;
  // partial selectors created once only
  abstract static class PartialSelector <T> implements Base.Selector<String> {
    T arg0;
  PartialSelector<A> selectorA = new PartialSelector<A> () {
    public String apply (A arg1) {
      return "AA";// "DoubleDispatchSelector received A(" + arg0.value + ") A(" + arg1.value + ")";
    public String apply (B arg1) {
      return "AB"; // "DoubleDispatchSelector received A(" + arg0.value + ") B(" + arg1.value + ")";
    public String apply (C arg1) {
      return "AC"; // "DoubleDispatchSelector received A(" + arg0.value + ") C(" + arg1.value + ")";
  PartialSelector<B> selectorB = new PartialSelector<B> () {
    public String apply (A arg1) {
      return "BA"; // "DoubleDispatchSelector received B(" + arg0.value + ") A(" + arg1.value + ")";
    public String apply (B arg1) {
      return "BB"; // "DoubleDispatchSelector received B(" + arg0.value + ") B(" + arg1.value + ")";
    public String apply (C arg1) {
      return "BC"; // "DoubleDispatchSelector received B(" + arg0.value + ") C(" + arg1.value + ")";
  PartialSelector<C> selectorC = new PartialSelector<C> () {
    public String apply (A arg1) {
      return "CA"; // "DoubleDispatchSelector received C(" + arg0.value + ") A(" + arg1.value + ")";
    public String apply (B arg1) {
      return "CB"; // "DoubleDispatchSelector received C(" + arg0.value + ") B(" + arg1.value + ")";
    public String apply (C arg1) {
      return "CC"; // "DoubleDispatchSelector received C(" + arg0.value + ") C(" + arg1.value + ")";
// external double dispatch using typeTag
class DoubleDispatchOnTypeTags implements Base.Functor2<String> {
  public String apply (Base any0, Base any1) {
    switch ( (any0.typeTag << 4) | any1.typeTag ) {
      case 0xAA: return apply((A)any0, (A)any1);
      case 0xAB: return apply((A)any0, (B)any1);
      case 0xAC: return apply((A)any0, (C)any1);
      case 0xBA: return apply((B)any0, (A)any1);
      case 0xBB: return apply((B)any0, (B)any1);
      case 0xBC: return apply((B)any0, (C)any1);
      case 0xCA: return apply((C)any0, (A)any1);
      case 0xCB: return apply((C)any0, (B)any1);
      case 0xCC: return apply((C)any0, (C)any1);
      default: throw new IllegalArgumentException();
  public String apply (A arg0, A arg1) {
    return "AA"; // "DoubleDispatchOnTypeTags received A(" + arg0.value + ") A(" + arg1.value + ")";
  public String apply (A arg0, B arg1) {
    return "AB"; // "DoubleDispatchOnTypeTags received A(" + arg0.value + ") B(" + arg1.value + ")";
  public String apply (A arg0, C arg1) {
    return "AC"; // "DoubleDispatchOnTypeTags received A(" + arg0.value + ") C(" + arg1.value + ")";
  public String apply (B arg0, A arg1) {
    return "BA"; // "DoubleDispatchOnTypeTags received B(" + arg0.value + ") A(" + arg1.value + ")";
  public String apply (B arg0, B arg1) {
    return "BB"; // "DoubleDispatchOnTypeTags received B(" + arg0.value + ") B(" + arg1.value + ")";
  public String apply (B arg0, C arg1) {
    return "BC"; // "DoubleDispatchOnTypeTags received B(" + arg0.value + ") C(" + arg1.value + ")";
  public String apply (C arg0, A arg1) {
    return "CA"; // "DoubleDispatchOnTypeTags received C(" + arg0.value + ") A(" + arg1.value + ")";
  public String apply (C arg0, B arg1) {
    return "CB"; // "DoubleDispatchOnTypeTags received C(" + arg0.value + ") B(" + arg1.value + ")";
  public String apply (C arg0, C arg1) {
    return "CC"; // "DoubleDispatchOnTypeTags received C(" + arg0.value + ") C(" + arg1.value + ")";
// test harness
public class Dispatch {
  static Base[] items0 = { new A("red"),   new B(0.1), new C(1) };
  static Base[] items1 = { new A("green"), new B(0.2), new C(2) };
  static long time (Base.Functor2 functor, int iterations) {
    final long start = System.currentTimeMillis();
    for (int iter = 0; iter < iterations; ++iter)
      for (Base item0 : items0)
        for (Base item1 : items1)
          functor.apply(item0, item1);
    final long finish = System.currentTimeMillis();
    return finish - start;
  public static void main (String ...args) throws Exception {
    int iterations = args.length > 0 ? Integer.parseInt(args[0]) : 100000;
    for (int run = 0; run < 7; ++run) {
      System.out.println("DoubleDispatchSelector1:  " + time(new DoubleDispatchSelector1(), iterations));
      System.out.println("DoubleDispatchSelector2:  " + time(new DoubleDispatchSelector2(), iterations));
      System.out.println("DoubleDispatchOnTypeTags: " + time(new DoubleDispatchOnTypeTags(), iterations));
} The reason the string concatenations are commented out is that with that amount of work, it doesn't matter which one you use. If you have a lot less work in the methods, using tags is more efficient:
DoubleDispatchSelector1:  807
DoubleDispatchSelector2:  714
DoubleDispatchOnTypeTags: 281Deeper dispatches are possible, but N^^3 or more methods are rather a lot to handle. The typeTags variant gives direct access to the individual methods, which the selectors can be adjusted to do with an extra indirection. The typeTags variant isn't checked for type safety by the compiler.
Edited by: pm_kirkham on 01-Apr-2008 21:01

Similar Messages

  • Multiple Dispatcher in The Landscape

    Hello Folks,
    We are using web dispatcher for our ECC systems. Now we are planning to extend this to our other systems in the land scape llike EP, BI, BO etc..
    Request you to share your thoughts planning the web dispatcher in the landscape and following concerns
    Scenarios:
    A. Multiple systems in a single web dispatcher
    B. Indepedent web dispatchers for each landscape.
    and
    C. if we can go with option B how it would be feasible to put multiple web dispatchers in a single host equipped with high CPU and memory.
    Waiting for your response
    Thanks in advance
    Satyabrat

    Hi Tomas,
    I want to setup same hostname with different port as now we are planning to use only one WD for all SAP systems.
    can you please guide me what shoudl be the parameter need to be maintained in the profile parameter.
    Please refer below parameters in my profile parameter.
    # Accesssability of Message Server
    rdisp/mshost = ECC HOST
    ms/http_port = 8100
    ms/https_port = 8443
    rdisp/mshost = Portal HOST
    ms/http_port = 8101
    ms/https_port = 8443
    # Configuration for medium scenario
    icm/max_conn = 500
    icm/max_sockets = 1024
    icm/req_queue_len = 500
    icm/min_threads = 10
    icm/max_threads = 50
    mpi/total_size_MB = 80
    # SAP Web Dispatcher Ports
    icm/server_port_0 = PROT=HTTP,PORT=6666
    #icm/server_port_1 = PROT=HTTP,HOST=localhost,PORT=81$$
    icm/HTTP/admin_0 = PREFIX=/sap/admin,DOCROOT=$(DIR_DATA)$(DIR_SEP)icmandir,AUTHFILE=$(icm/authfile),PORT=81$$
    icm/server_port_1 = PROT=HTTP,PORT=7777,TIMEOUT=900,PROCTIMEOUT=900
    icm/server_port_2 = PROT=HTTPS,PORT=8443,TIMEOUT=900,PROCTIMEOUT=900
    icm/keep_alive_timeout = 900
    icm/host_name_full = <Hostname webdisptacher>.abc.com
    # Start webdispatcher
    _WD = $(DIR_EXECUTABLE)\sapwebdisp$(FT_EXE)
    Start_Program_00 = local $(_WD) pf=$(_PF)
    SETENV_01 = SECUDIR=$(DIR_INSTANCE)/sec
    # Parameters for the SAP Cryptographic Library
    ssl/ssl_lib = E:\usr\sap\QWT\W01\sec\sapcrypto.dll
    ssl/server_pse = E:\usr\sap\QWT\W01\sec\SAPSSLS.
    Thanks & Regards,
    Satyabrat

  • Copy multiple dispatch vi to new child class

    Hi, I have just started with LVOOP and while I'm pretty sure I have a good understanding of the overall theme, there is one problem I foresee if I continue.
    Situation:
    BoardType is parent of classes CC2600 and CC1300. Currently the child classes are just empty place holders.
    Almost all the methods in the child classes will be of dynamic dispatch type (currently only one).
    From what I understand a dynamic dispatch must be available in all child classes plus parent class in order to work as intended. 
    Problem:
    If I would go forward and implementing LVOOP this would require approx 30 dynamic dispatch vis for each class. I can right click but for just these two children that's 60 + 30 vis I must create manually. I would much prefer just to create a template once and then just basically drag and drop 30+ new vis for each new class that is created.
    Is there a way I can define a set of template dispatch vis in the parent BoardType and have them added to all the child classes? 
    I tried the save as copy, but the problem is that I still have to replace the connector pane to represent the new owning class.
    If it helps here's a very basic block diagram of what's going to happen, just after Reset.vi there will be a lot of other dynamic dispatch vis.
    Thanks in advance.
    Michael

    From the OP it sounded like you were literally just copying from the parent.
    What I tend to do is finish one child class and then save a copy to a new name and change the internal data (if required) and DD vis (if required).
    I do agree though that these kinds of operations could be hugely simplified using helper programs.  Give the link provided by others a try.
    Shane.
    Say hello to my little friend.
    RFC 2323 FHE-Compliant

  • Multiple dispatch and Symmetric methods - Where Does That Code Live?

    Hi all.
    I am stuck with the above problem, which looks to be a very common and fundamental one. Supposing I have some sort of relation or operation to be performed on various different pairs (or n-tuples) of classes of object. Where does this code belong, given that it is not sole property of any one of the classes, but a kind of property of the collection of classes?
    An bad example for me to bring up, but one that neatly illustrates the point, is the equals method. In order to retain the symmetric and transitive properties of the equals method, and object can only make judgement calls about it being equal to another object of it's own type. This prevents the concept of equivalency from crossing between types.
    In order to compare a with b (if a and b are of different types), b must supply some sort of representation of itself as an a, then the comparison statement a.equals(b.asA()); must be called.
    This of course means b must supply an 'asXXX()' method for each class XXX it wishes to equate itself to. Furthermore, by an extension of the equals contract for symmetricality, the method AsB() in class A (if it exists) must be such that, if a.AsB() .equals (b), then b.AsA.equals( a ).
    This sort of design is unfeasible for obvious reasons, the main reason being that it is impossible to anticipate evey case where an instance of class A could reasonably be compared to an instance of some other class X.
    The other annoyance is all that hard work of providing methods to equate A with something else, would go unused for 99% of the time.
    With this in mind, I was thinking. Suppose in some program environment, we have only 3 classes, A, B, and C, such that:
    {A,B} can be meaningfully compared
    {B, C} and {A, C} cannot.
    It would be OK to supply code (somewhere) for comparing A's with B's. We also know that under no circumstances will an A or a B, and a C, ever need to be compared for equality.
    Supposing an extension of this environment were created, introducing class D.
    {D, A} and {D, B} can be meaningfully compared.
    Now, neither A nor C knows what a D is, or how to compare themselves to it. But D was developed with A, B and C in mind, and contains logic for the various comparisons (with A and with B). An obvious idea for this is to let D bring it's new code into play, by registering these new comparison functions in the environment somehow.
    Supposing instead that equality comparison was delegated to some third party, instead. This third party contains a table of pairs of classes, which act as keys to look up a comparison object.
    So, when class A is loaded, something of the sort happens:
    public class A {
        static {
            Equals.comparer.addEntry(A.class, B.class, new EqualsMethod() {
               // details of the EqualsMethod interface implementation go here
    public class B {
        static {
            // since equals is symmetric, this method clashes with the above in A
            // This could happen...
            Equals.comparer.addEntry(B.class, A.class, new EqualsMethod() {
               // ... different approach to the above
    public class D {
        static {
            Equals.comparer.addEntry(D.class, A.class, new EqualsMethod() {
            Equals.comparer.addEntry(D.class, B.class, new EqualsMethod() {
        } // Ds can now be compared with Bs and As. They can now be compared with Ds
    }There is a problem with the above. As can clearly be seen, there are 3 unique situations that might occur between two classes (call them X and Y).
    o One of X or Y contains code to compare them both.
    o Neither X nor Y contain code to compare the two. X equals Y is always false
    o Both X and Y contain code to compare the two.
    The third causes the problem. What if X and Y disagree on how to compare themselves? Which method gets chosen? The only solution would be to let whosever static initialiser gets called first be the one to supply the code.
    I said before that equals was a bad example to bring up. this is because the usage of equals and the concept of equality in java is already well defined, and works just fine. However, in my own pet project at the moment, I have run into the same problems as outlined above.
    I am currently assembling a generic pattern API for use in various other applications I am writing (I was finding that I was writing code for matching objects to patterns, in different guises, quite frequently, so I made the decision to refactor it into its own package). An important part of the API is the section that handles the logic for combining patterns, ie with AND, OR and NOT operations.
    The Pattern interface is this:
    interface Pattern<E> {
         public boolean match(E toMatch);
         public Pattern<E> not();
         public Pattern<E> or(Pattern<E> other);
         public Pattern<E> and(Pattern<E> other);
    }There are a few basic Patterns:
    TruePattern<E> - a pattern that always returns true no matter what E is passed for it toMatch
    FalsePattern<E> - self-explanatory.
    ExactValuePattern<E> - true if and only if the E that it is passed toMatch is .equal to the E that this pattern was constructed with.
    NotPattern<E> - a pattern that contains another pattern, and returns true for any E that returns does not match it's contained pattern. Used for when the contained pattern cannot be logically reduced to one pattern under the NOT method in the Pattern interface
    AndPattern<E> - a pattern that contains 2 other patterns, and returns true for some E iff both contained patterns return true for that E. Used for when the 2 patterns cannot be logically reduced into one pattern via the AND method in the Pattern interface
    OrPattern<E> - self explanatory
    RangePattern<E extends Comparable <E>> - a pattern for comparing if some Comparable lies between two other comparables.
    Every pattern has the opportunity to provide a reduction, when combined with another pattern through And or Or. For example, any pattern AND a FalsePattern can be reduced just the FalsePattern. any pattern OR a TruePattern can be reduced to just the TruePattern.
    The methods AND and OR from the Pattern interface present the same problems as the .equals() example I was using before.
    o AND and OR are symmetric operations
    o There exist situations where two patterns of unrelated class could be meaningfully combined (and reduced) under these two operations.
    Example: The pattern on Integers '0 < X < 3' and 'X is 5' can be reduce to the FalsePattern
    Example: The pattern on Doubles '0 < X <= 10' or 'X is 5.5' or 'X is 7.2' can be reduced to '0 < X <= 10'.
    Example: The pattern on Integers ('0 <= X <= 5' and 'X is not 0') or ('X is 6') or ('x is 7') can be reduced to '1<=X<=7'.
    So the question is, where does the code belong? a.and(b) should return the same as b.and(a), but both b and a may well disagree as to what happens when they are combined under and. At present, both a and b need to supply their own separate implementations. Clearly though, the code for combining patterns A and B belongs to neither A alone, not B alone, but to A and B as a whole.
    Thanks in advance, and sorry for this overlong post.

    So the equivalent thing in my scenario would be an
    AndAnator, and an OrAnator? :)
    The thing is, it would be nice for comparison between
    A and B to take place automatically, without the poor
    coder having to maintain a reference to a Comparator
    and invoke the comparison method each time. Likewise
    in my situation, it'd be nice to say A.or(B) instead
    of andAnator.and(A,B), yet have all the goodness of a
    third party doing the comparison (or in this case,
    the anding).
    I am going to go and test this all out, but do you
    have any suggestions on a good structure? I think it
    would involve pulling the and/or/not methods from the
    interface (this appeals, as many implementors may not
    wish to supply logic for running these methods
    anyhow), and then putting them... somewhere else.I didn't consider your speicifc problem very deeply because after such a long detailed explanation I figured you'd be up for kicking around the idea for a while.
    In your case, I see that you would want to be able to call the and and or methods on the Objects themselves. Luckily, in this case, I think you can have your cake and eat it too.
    You can make your and and or methods fa�ades to the third party 'referee'. This way you can enfore symmetry. It's difficult (if not impossible) to enoforce transitivity with this design but I think you don't even need that in this case. That is if a == b and b == c then a == c should be true but if a and b and b and c then a and c is not necessarily true. In your case, it may not even make sense.

  • Java Connector (Jco) sizing in a NW2004s cluster

    Hi All,
    We have an EP7 cluster with 3 x SAP J2EE engines (multiple dispatcher and server processes running on multiple hardare).  I am looking at sizing the Jco connection pools for ESS and MSS applications.  This will involve changing the parameters against the Jco connection destinations - like 'maximum pool size' and 'maximum connections'.  My question is, if for instance I was to change the 'maximum pool size' from the default value '5' -> '50', being that we have 3 J2EE engines, does this mean that potentially we could have 150 (3 x 50) connections allowed to the backend ABAP system ?  Or are these settings global ? I can't seem to find a definite answer to this.
    Thanks for your time,
    Regards
    Anthony

    See if these links help explain further:
    http://help.sap.com/saphelp_nw2004s/helpdata/en/3a/3b1b40fcdd8f5ce10000000a155106/frameset.htm
    http://help.sap.com/saphelp_nw2004s/helpdata/en/6f/1bd5c6a85b11d6b28500508b5d5211/frameset.htm
    http://help.sap.com/saphelp_nw2004s/helpdata/en/8b/91222fa9e611d6b28f00508b6b8a93/frameset.htm
    http://help.sap.com/saphelp_nw2004s/helpdata/en/09/a4a9e1d51d11d6b2c200508b5d5c51/frameset.htm
    http://help.sap.com/saphelp_nw2004s/helpdata/en/e8/bda7c0cef411d6b2bd00508b5d5211/frameset.htm

  • Simple polymorphism question

    Hi,
    I'm trying to get the following behavior in Java. Does anyone have any insight?
    interface Type{}
    class TypeA implements Type{}
    class TypeB implements Type{}
    class TypeC implements Type{}
    class TypeZ implements Type{}
    Class Differentiator
      void method(TypeA a, TypeB b, TypeC c){}
      void method(TypeA a, TypeA a2, TypeC c){}
      void method(TypeA a, TypeB b, TypeZ z){}
    Class MainProgram
      public static void main(String[] args)
        Type obj1 = new TypeA();
        Type obj2 = new TypeF();
        Type obj3 = new TypeZ();
        Differentiator D = new Differentiator();
        D.method(obj1,obj2,obj3);
    }from my main() function. It should call the appropriate method() depending on the types of object that are passed to it. If none of the defined methods fit, it should throw a NotImplemented exception.
    Seems like a pretty straightforward problem. But I can't find a solution.
    Thanks a lot
    Cuppo
    Edited by: CuppoJava on Dec 3, 2007 3:54 AM

    You're basically looking for dynamic/multiple dispatch, which is not something that is part of Java. If you want to simulate that behavior, you will have to use reflection.
    http://www.lshift.net/blog/2006/06/23/multimethods-for-java
    might be a good starting point

  • Using a single NetConnection instance to dispatch multiple calls to backend

    I have a scenario where calls to backend have to be dispatched in parallel because the calls are independent and dispatching them serially would cost performance.
    If I use a single instance of NetConnection to send multiple requests to backend -  one after the other without waiting for responses to previous requests to arrive - and there is a NetStatus event once the calls have been dispatched because, for example, the network connection went down, is it possible to find out which of the calls succeeded and which ones failed? Is it safe to assume that if the onResult function of a particular call's responder was not invoked, then that request did not reach the backend? If not, what is the recommended way to implement this? Should a separate instance of NetConnection be used for each call?  How expensive would it be? How are multiple NetConnection instances connected to the same endpoint handled under the hood?
    Thanks.

    Joe,
    I don´t know a specific reference for it, I remembered it because when I was looking the documentation on the site, I saw the reference "Support for multiple database connections" in the URL: APEX Listener New Features 2.0&lt;/title&gt;&lt;meta name=&quot;Title&quot; content=&quot;APEX Listener New Features 2.0…
    I´ve tried to use APEX listener some time ago, but in a earlier version together with glassfish. So, since for me was only one database, I created the necessary amount of DAD´s on my database, each one for a specific port.
    Check the link and you´ll see the same information I saw.
    Thanks.
    José Valdézio
    "Neo, everything that Oracle told me, became true, except extinguish bugs in a first release."

  • Multiple Weblogic nodes on single Windows server  - Dispatcher question?

    Hi All,
    My experience is with other J2EE web servers (SAP's Netweaver predominantly) and typical installations on this platform include the installation of a dispatcher J2EE node which balances load across potentially multiple J2EE nodes on a single server. Does Weblogic have a similar set-up, as it appears when you create multiple nodes in Weblogic, you need to set-up a load balancer to achieve this same effect (that is installed by default on other platforms).
    Obviously creating a single node is pretty useless for the majority of production installations; hence what is the recommended option (without setting up a dedicated load balancer) to achieve this on a single (albeit large) server?
    Thanks,
    Matt

    Hi,
    I had just remembered another option, we can set up weblogic as webserver which does the load balancing. Below are the two ways you can do that.
    1. While creating the domain using "config.sh" you will get an option to set up "weblogic server as webserver". This option is enabled only on condition "cluster must be created, and few managed servers needs to assigned to cluster". For example if we create 3 managed servers and we assign 2 managed to cluster then "Http Proxt screen" would be enabled where remaining server can be set up as "http proxy webserver".
    2. Below is the lengthy procedure.
    a. Create a standalone weblogic server.
    b. We need to create a dummy war, which just contains below "web.xml" adn "weblogic.xml", let me know if you have trouble creating this war file.
    Contents of "web.xml"
    <?xml version='1.0' encoding='UTF-8'?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <servlet>
    <!-- Add HTTPClusterServlet -->
    <servlet-name>HttpClusterServlet</servlet-name>
    <servlet-class>weblogic.servlet.proxy.HttpClusterServlet</servlet-class>
    <init-param>
    <param-name>WebLogicCluster</param-name>
    <param-value>127.0.0.1:7003|127.0.0.1:7005|127.0.0.1:7007</param-value>
    </init-param>
    </servlet>
    <!-- Add HTTPClusterServlet Mapping elements -->
    <servlet-mapping>
    <servlet-name>HttpClusterServlet</servlet-name>
    <url-pattern>/</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>HttpClusterServlet</servlet-name>
    <url-pattern>*.jsp</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>HttpClusterServlet</servlet-name>
    <url-pattern>*.htm</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>HttpClusterServlet</servlet-name>
    <url-pattern>*.html</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>HttpClusterServlet</servlet-name>
    <url-pattern>browsestore</url-pattern>
    </servlet-mapping>
    </web-app>
    Contents of "weblogic.xml" . This deployment descriptor is used to deploy this application as "default application".
    <?xml version='1.0' encoding='UTF-8'?>
    <weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/90" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <!-- Add the context root here -->
    <context-root>/</context-root>
    </weblogic-web-app>
    c. Now deploy this war file to standalone weblogic server.
    d. Lets suppose you had deploy application "vas.war" on managed server "VASMS1", "VASMS2", which are running on host "vasunix1" and "vasunix2" on ports 8002. You can access the application directly "http://vasunix1:8001/vas" or "http://vasunix2:8002/vas".
    Now since you had set up "http proxy webserver" which does the load balancing, you can directly hit "http proxy webserver" url and it redirects traffic to "VASMS1" or "VASMS2". Lets suppose "Http proxy webserver" "VASMS3" is running on "vasunix1" on port "8003". You can access the application "http://vasunix1:8003/vas", this request is directed to MS1 or MS2.
    I hope this is what you are looking for. Have great day.
    Vijay Bheemineni.

  • Single Web Dispatcher for Multiple SAP Systems

    Having read a number of posts & S-Notes, I found that Web Dispatcher 7.2 is capable of routing between multiple SAP instances.
    But despite having troubleshooted, I am unable to make it work. I have two separate installations ERP & Portal on the same host, but my web dispatcher only routes to one of them at the same time. Simultaneous access to these 2 systems is not possible either with URL or Port control procedure mentioned at url http://help.sap.com/saphelp_nw72/helpdata/en/c5/ec466f5544409982c7d3ca29ce1ad3/frameset.htm
    Can anyone point an error in my below mentioned configuration of web dispatcher file.
    I want requests on port 8853 of my web-dispatcher to be routed to system DEV &
    the requests on port 8843 of my web-dispatcher to be routed to system DEP
    rdisp/mshost = sapdeverp
    ms/http_port = 8100
    icm/server_port_0 = PROT=HTTP,PORT=8853
    icm/server_port_1 = PROT=HTTP,PORT=8843
    wdisp/system_0 = SID=DEV, MSHOST=sapdeverp, MSPORT=8100, SRCSRV=*:8853
    wdisp/system_1 = SID=DEP, MSHOST=sapdeverp, MSPORT=8102, SRCSRV=*:8843
    Can we mention multiple message servers instead of single message server "rdisp/mshost = sapdeverp
    ms/http_port = 8100" ?
    Any suggestions ?

    Very right in mentioning this point coz myself have been confused over it but if I remove these lines & execute the -checkconfig:
    then it states as below:
    Checking SAP Web Dispatcher Configuration
    =========================================
    maximum number of sockets supported on this host: 8192
    Server info will be retrieved from host: : with protocol: http
    Checking connection to message server...
    ERROR: Connection to message server failed: NIESERV_UNKNOWN
    Check ended with 1 errors, 0 warnings
    More over accessing the servers give the following error:"
    500 Dispatching Error
    Error: -26
    Version: 7000
    Component: HTTP_ROUTE
    Date/Time: Mon Nov 29 17:28:11 2010 
    Module: http_route.c
    Line: 3139
    Server: solomon__03
    Error Tag:
    Detail: no valid destination server available for '!ALL' rc=13
    I have tried this actually, even tried the option ms/server_port_0 & 1 to replace ms/http_port but it didnt work either.
    Any more ideas.. ?

  • Dispatch center - Select multiple tasks for scheduling at the same time

    Hi!
    I need a consultation regarding Dispatch center. Is there a functionality to select multiple tasks for scheduling at the same time for one resource?
    Please, guys, this is urgent.
    Jan

    You can schedule a single task or multiple tasks automatically directly from the
    dispatch center. The scheduling criteria applied come from Advanced Scheduler.
    Make Sure, you have the advanced scheduler. With out Advanced Scheduler and by just using Advice, you can only assign one task at a time.
    HTH
    ps: for more information, refer Field Service User Guide, "Scheduling Tasks"

  • KeyboardFocusManager dispatches only one event while multiple are fired

    I'm writing the game Achtung die Kurve, or 'Zatacka' in Java.
    It's in fullscreen and there are multiple players with their own controls.
    Now, to catch the KeyEvents (controls) for each Player, the Player objects get created with the following line in the constructor:
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(this);However, when multiple players are holding (KEY_PRESSED) different buttons at the same time, only the 'last' one gets processed.
    The following example shows my point:
    import java.awt.GridLayout;
    import java.awt.KeyEventDispatcher;
    import java.awt.KeyboardFocusManager;
    import java.awt.event.KeyEvent;
    import javax.swing.*;
    public class main
        private static JTextArea txt;
        public static void main(String[] args)
            new main();
        public main()
            JFrame f = new JFrame();
            f.setSize(300, 700);
            f.setVisible(true);
            f.setDefaultCloseOperation(f.DISPOSE_ON_CLOSE);
            f.setLayout(new GridLayout());
            txt = new JTextArea();
            txt.setEditable(false);
            f.add(txt);
            Listener l1 = new Listener(KeyEvent.VK_Z);
            Listener l2 = new Listener(KeyEvent.VK_X);
        class Listener implements KeyEventDispatcher
            int ktlt;
            public Listener(int keyToListen)
                ktlt = keyToListen;
                KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(this);
            public boolean dispatchKeyEvent(KeyEvent e)
                if (e.getID() == e.KEY_PRESSED && e.getKeyCode() == ktlt)
                    txt.append("" + ktlt + "\n");
                    return true;
                return false;
        }}Try holding the 'z' and 'x' buttons at the same time (for a short period).
    What you would expect is that the output will contain the key codes for both of the buttons, alternatively.
    What you see, is that the textarea gets filled with only the 'last' key that is being pressed.
    What am I doing wrong here?
    Edited by: Tails on 12-jan-2009 21:22

    Tails wrote:
    That's kind of a problem as I am on Linux.As am I
    KeyEvents are broken on linux: every key press action generates KEY_TYPED, KEY_RELEASED and KEY_PRESSED events at the same time, which means that's worthless...I got it to work for my purposes. What is the alternative?

  • Multiple crashes- Crashed Thread:  0  Dispatch queue: com.apple.main-threa

    Am having numerous applications crashing with what seems to be a common error coming up (as below). Aperture, Photoshop, Money, Pacifist - all have had the same so far.
    Have attempted to repair disk permissions and reinstall SL again. Am thinking at the moment I should revert to my cloned drive of Leopard. Really disappointed and worried at the moment.
    Exception Type: EXCBADACCESS (SIGBUS)
    Exception Codes: KERNPROTECTIONFAILURE at 0x0000000000000011
    Crashed Thread: 0 Dispatch queue: com.apple.main-thread

    I am getting the same thing OVER and OVER! I have wiped my hard drive and reinstalled all of my applications (5 times) and still get the same old thing. It is happening in Safari, Mail (which is also displaying all of my incoming messages as arriving one our earlier than they do), CS4 (take your pick of apps there), excel, and Logic Pro. I don't thinkI have any issues with Adobe Lightroom, or word. Somebody needs to come up with something other than finger pointing here! I can't work, right now all I have is an $8000 paperweight. FWIW my MacBook Pro seems stable, although I don't use it much for anything surfing the web and email these days.
    HELP!

  • When to acknowledge when dispatching using multiple threads?

    So on a project I'm working on I read from a queue and I dispatch to a thread pool that has worker threads and the general idea is that I never want to acknowledge a message until I know for sure that I've processed it otherwise it risks becoming lost.
    There are two approaches
    1. is to acknowledge the message immediately after the details have been written to a working table and then in the event that the client restarts you pickup messages from this table prior to processing any new ones from the queue. upon processing each message you update it's state or delete the row from this table to reflect that it's no longer working.
    2. another approach is to queue up acknowledgements in the main message listener thread such that as each worker thread completes it's job it enqueues the message for acknowledge by the main delivery thread (async). ie. the same thread that is picking up the messages. So after pulling a message from the queue and having dispatched it you then at the end of the cycle work thru the queue to acknowledge the messages that has been queued up by the worker threads to be acknowledged. One thing about this is that acknowleding a message implicitly acknowledges all those prior unacknowledged messages it's probably overkill to be acknowledging every message in the "queue." You just want to acknowledge the most recent one.
    I believe that option 2 results in less work since there's no round trips to the database necessary to maintain a working table.
    Websphere's MQ in JMS requires that you acknowledge in the delivery thread so unless you do it immediately or after processing each message you have to maintain a working table if you want to guarantee that any message pulled off the queue was actually processed and not lost along the way.

    steffi wrote:
    So on a project I'm working on I read from a queue and I dispatch to a thread pool that has worker threads and the general idea is that I never want to acknowledge a message until I know for sure that I've processed it otherwise it risks becoming lost.
    There are two approaches
    1. is to acknowledge the message immediately after the details have been written to a working table and then in the event that the client restarts you pickup messages from this table prior to processing any new ones from the queue. upon processing each message you update it's state or delete the row from this table to reflect that it's no longer working.
    2. another approach is to queue up acknowledgements in the main message listener thread such that as each worker thread completes it's job it enqueues the message for acknowledge by the main delivery thread (async). ie. the same thread that is picking up the messages. So after pulling a message from the queue and having dispatched it you then at the end of the cycle work thru the queue to acknowledge the messages that has been queued up by the worker threads to be acknowledged. One thing about this is that acknowleding a message implicitly acknowledges all those prior unacknowledged messages it's probably overkill to be acknowledging every message in the "queue." You just want to acknowledge the most recent one.
    I believe that option 2 results in less work since there's no round trips to the database necessary to maintain a working table.certainly. but how exactly does it achieve your reliability goals from the first paragraph?
    Websphere's MQ in JMS requires that you acknowledge in the delivery thread so unless you do it immediately or after processing each message you have to maintain a working table if you want to guarantee that any message pulled off the queue was actually processed and not lost along the way.sounds about right, yes.

  • Multiple JButtons inside JTable cell - Dispatch mouse clicks

    Hi.
    I know this subject has already some discussions on the forum, but I can't seem to find anything that solves my problem.
    In my application, every JTable cell is a JPanel, that using a GridLayout, places vertically several JPanel's witch using an Overlay layout contains a JLabel and a JButton.
    As you can see, its a fairly complex cell...
    Unfortunately, because I use several JButtons in several locations inside a JTable cell, sometimes I can't get the mouse clicks to make through.
    This is my Table custom renderer:
    public class TimeTableRenderer implements TableCellRenderer {
         Border unselectedBorder = null;
         Border selectedBorder = null;
         public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                   boolean hasFocus, int row, int column) {
              if (value instanceof BlocoGrid) {
                   if (isSelected) {
                        if (selectedBorder == null)
                             selectedBorder = BorderFactory.createMatteBorder(2,2,2,2, table.getSelectionBackground());
                        ((BlocoGrid) value).setBorder(selectedBorder);
                   } else {
                        if (unselectedBorder == null)
                             unselectedBorder = BorderFactory.createMatteBorder(2,2,2,2, table.getBackground());
                        ((BlocoGrid) value).setBorder(unselectedBorder);
              return (Component) value;
    }and this is my custom editor (so clicks can get passed on):
    public class TimeTableEditor extends AbstractCellEditor implements TableCellEditor {
         private TimeTableRenderer render = null;
         public TimeTableEditor() {
              render = new TimeTableRenderer();
        public Component getTableCellEditorComponent(JTable table, Object value,
                boolean isSelected, int row, int column) {
             if (value instanceof BlocoGrid) {
                  if (((BlocoGrid) value).barras.size() > 0) {
                       return render.getTableCellRendererComponent(table, value, isSelected, true, row, column);
             return null;
        public Object getCellEditorValue() {
            return null;
    }As you can see, both the renderer and editor return the same component that cames from the JTable model (all table values (components) only get instantiated once, so the same component is passed on to the renderer and editor).
    Is this the most correct way to get clicks to the cell component?
    Please check the screenshot below to see how the JButtons get placed inside the cell:
    http://img141.imageshack.us/my.php?image=calendarxo9.jpg
    If you need more info, please say so.
    Thanks.

    My mistake... It worked fine. The cell span code was malfunctioning. Thanks anyway.

  • Not Running on the Event Dispatch thread, but UI still freezes

    The environment: I am currently working on an application that requires some heavy lifting in response to user input on a UI. To do this I am using a version of SwingWorker that was backported from java 1.6 to java 1.5 in conjunction with a slew of custom threads.
    The problem: I am currently running into an issue where I am not operating on the Event Dispatch thread (checked by doing a javax.swing.SwingUtilities.isEventDispatchThread()) but the UI is still freezing during this section. The operation involves a loop with about 2000 iterations and contains several file accesses. I have thought about how to make a new thread to perform the same operation, but I do not see how it would be any different since as it is I am not on the EDT. The call is being made from doInBackground and specifically the piece that is slowing things down is the File Accesses (2 for every iteration of the loop). At this point I am not sure how to go about resolving the issue. Any one have any suggestions?

    I am not operating on the Event Dispatch threadThat is the problem. Use multiple threads for GUI, which should delegates to the EDT, and your app logic.

Maybe you are looking for