Implementing Singleton Pattern in ESB

How do I go about implementing a singleton pattern within the ESB. Example usage would be for a cache. Prior to making an expensive service call I want to make sure that the data does not already exist within the cache.

Have a look at metalink note 746108.1
cheers
James

Similar Messages

  • Serializing object of class implementing Singleton Pattern

    hi ,
    if i've a object of a singleton pattern based class and i seriailize that and when i'm desrializing that, i 'll get the object back, but on calling getInstance() method for my singleton class, it will agian call constructor because for the class's static object reference is null, i need to avoid this, for this i've written a setInstance method, which sets the Singleton class's static refernce to the object i desialized, which is fine, but it defeats the singleton pattern
    can anybody suggest me some other way of achieving this...

    If you are trying to deserialize a Singleton implement the Object readResolve() method.
    http://java.sun.com/javase/6/docs/platform/serialization/spec/input.html#5903
    ~Ryan

  • GC + Singleton pattern

    I have a class implementing singleton pattern, which has a private static variable meant to be used by all other classes.
    public class MyClass {
    private static MyClass shareVar;
    private MyClass() {
    // do something
    public static MyClass getInstanceof() {
    if( shareVar == null )
    shareVar = new MyClass();
    return shareVar;
    // other methods ...
    I have noticed that this instance is never garbage collected.
    Is the static variable holding back the GC?
    Any other alternatives for this?
    Thanks

    I have noticed that this instance is never garbage
    collected.Which is exactly the way it should work. If the instance were GC'ed before MyClass is unloaded, shareVar would be a dangling pointer.
    Is the static variable holding back the GC?Yes.

  • Serializing a class that implements the Singleton pattern

    Hello,
    I am relatively new to Java and especially to serialization so the answer to this question might be obvious, but I could not make it work event though I have read the documentation and the article "Using XML Encoder" that was linked from the documentation.
    I have a class that implements the singleton pattern. It's definition is as follows:
    public class JCOption implements Serializable {
      private int x = 1;
      private static JCOption option = new JCOption();
      private JCOption() {}
      public static JCOption getOption() { return option; }
      public int getX() { return x; }
      public void setX(int x) { this.x = x; }
      public static void main(String args[]) throws IOException {
        JCOption opt = JCOption.getOption();
        opt.setX(10);
        XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream("Test.xml")));
        encoder.setPersistenceDelegate(opt.getClass(),  new JCOptionPersistenceDelegate());
        encoder.writeObject(opt);
        encoder.close();
    }Since this class does not fully comply to the JavaBeans conventions by not having a public no-argument constructor, I have create a class JCOptionPersistenceDelegate that extends the PersistenceDelegate. The implementation of the instantiate method is as follows:
      protected Expression instantiate(Object oldInstance, Encoder out) {
           Expression expression = new Expression(oldInstance, oldInstance.getClass(), "getOption", new Object[]{});
            return expression;
      }The problem is that the resulting XML file only contains the following lines:
        <java version="1.5.0_06" class="java.beans.XMLDecoder">
            <object class="JCOption" property="option"/>
        </java> so there is no trace of the property x.
    Thank you in advance for your answers.

    How about this:
    import java.beans.DefaultPersistenceDelegate;
    import java.beans.Encoder;
    import java.beans.Expression;
    import java.beans.Statement;
    import java.beans.XMLEncoder;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    public class JCOption {
        private int x = 1;
        private static JCOption option = new JCOption();
        private JCOption() {}
        public static JCOption getOption() { return option; }
        public int getX() { return x; }
        public void setX(int x) { this.x = x; }
        public static void main(String args[]) throws IOException {
          JCOption opt = JCOption.getOption();
          opt.setX(10);
          ByteArrayOutputStream os = new ByteArrayOutputStream();
          XMLEncoder encoder = new XMLEncoder( os );
          encoder.setPersistenceDelegate( opt.getClass(), new JCOptionPersistenceDelegate() );
          encoder.writeObject(opt);
          encoder.close();
          System.out.println( os.toString() );
    class JCOptionPersistenceDelegate extends DefaultPersistenceDelegate {
        protected Expression instantiate(Object oldInstance, Encoder out) {
            return new Expression(
                    oldInstance,
                    oldInstance.getClass(),
                    "getOption",
                    new Object[]{} );
        protected void initialize( Class<?> type, Object oldInstance, Object newInstance, Encoder out ) {
            super.initialize( type, oldInstance, newInstance, out );
            JCOption q = (JCOption)oldInstance;
            out.writeStatement( new Statement( oldInstance, "setX", new Object[] { q.getX() } ) );
    }   Output:
    <?xml version="1.0" encoding="UTF-8"?>
    <java version="1.5.0_06" class="java.beans.XMLDecoder">
    <object class="JCOption" property="option">
      <void property="x">
       <int>10</int>
      </void>
    </object>
    </java>

  • Implementing the Singleton pattern

    Has anyone implemented the singleton pattern in Forte? A singleton is simply ensuring that there is one unique instance of a class. In other OO languages I would create a class method which would use a class variable to hold onto the unique instance. Since forte doesn't have either of these (class methods or variables), I'm not sure how to do it. I thought of using named objects, but it seems like a heavy implementation. Any ideas.

    An SO with its shared=TRUE and anchored=TRUE?
    Venkat J Kodumudi
    Price Waterhouse LLP
    Internet: [email protected]
    Internet2: [email protected]
    -----Original Message-----
    From: [email protected] [SMTP:[email protected]]
    Sent: Monday, February 02, 1998 1:09 PM
    To: Venkat Kodumudi
    Subject: Implementing the Singleton pattern
    To: [email protected] @ Internet
    cc:
    From: [email protected] @ Internet
    Date: 02/02/98 12:36:02 PM
    Subject: Implementing the Singleton pattern
    Has anyone implemented the singleton pattern in Forte? A singleton is
    simply
    ensuring that there is one unique instance of a class. In other OO
    languages I
    would create a class method which would use a class variable to hold
    onto the
    unique instance. Since forte doesn't have either of these (class
    methods or
    variables), I'm not sure how to do it. I thought of using named
    objects, but it
    seems like a heavy implementation. Any ideas.

  • Use of Singleton pattern in Distributed environment

    Can somebody say why it is not advisable to use Singleton pattern for developing client server applications.

    Client-server does not imply distributed environment, IMHO. There are pretty simple C/S architectures where Singleton pattern is not generally a bad thing.
    Distributed environments usually have multiple VMs running, while the singleton pattern typically implemented is a per-VM singleton.

  • Is abap thread safe? Some question in Singleton pattern in ABAP

    Hi Grus,
    I have a very basic question but really make me headache...
    Recently I am learning the design pattern in ABAP and as you know in JAVA there is a key word "Synchronized" to keep thread safe. But in ABAP, I didn't find any key words like that. So does that mean ABAP is always a single thread language? And I found that there is a way looks like "CALL FUNCTION Remotefunction STARTING NEW TASK Taskname DESTINATION dest" to make multi-thread works. As you can see it use the destination, so does that mean actually the function module is always executed in a remote system, and in every system, it is always single thread?
    Could you help me on the question? Thanks a lot, grus
    And here comes up to my mind another question...It's a little bit mad but I think it may works....What if I set every attribute and method as static in the singleton class...Since as you can see it is already a singleton so every attribute in it should be only one piece. So then I don't even need to implement a get_instance( ) method to return the instance. Just call "class_name=>some_method( )" directly then singleton is achieved...What do you think?
    BR,
    Steve

    Steve,
    I've the same question, few days ago I tried to use the singleton in ABAP. In Java programming is possible to use the same reference in two sessions or programs, sharing attributes, methods and all data, but I could not do in ABAP.
    In my test I created a program with one global class using the singleton pattern, so I expected that when I run my program and see the reference returned after the get_instance method it should be equal to the same program run in another session, but the ABAP will create a new reference and instantiate again.
    So I deduced that the only way to share it between sessions in ABAP is using the ABAP Shared Memory Objects.
    I can be wrong, but I think that ABAP use a thread by user session (Each window) and we can't change it.
    Best regards.

  • Re: Singleton Pattern

    At PerSe Technologies, we have implemented the singleton pattern in our
    Enterprise Component Toolkit Framework. We have what we call our "shared
    data managers", which are visible to the appropriate architecture layer.
    We did not implement this as a service object and do not use a Forte
    "Shared" object. Instead, we use mutexes to control data locking ourselves
    which allows multiple tasks to execute against the shared data manager
    concurrently. This approach ensures us that we have one and only one copy
    of a given object at a time. Our approach also gives another benefit in
    that it caches frequently accessed data and has improved overall
    performance of our applications.
    Dustin Breese
    [email protected]
    Supervising Technical Consultant
    PerSe Technologies
    From: Mark Addesso <[email protected]>
    Date: Mon, 2 Feb 1998 12:36:02 -0500
    Subject: Implementing the Singleton pattern
    Has anyone implemented the singleton pattern in Forte? A singleton is =
    simply ensuring that there is one unique instance of a class. In other =
    OO languages I would create a class method which would use a class =
    variable to hold onto the unique instance. Since forte doesn't have =
    either of these (class methods or variables), I'm not sure how to do it.=
    I thought of using named objects, but it seems like a heavy =
    implementation. Any ideas.

    Is the danger that someone might make the Singleton
    cloneable really a the most important reason to make a
    Singleton non-extensible? I think not.It IS a good reason if cloning or subclassing it means
    you can end up with more than one in the same JVM. If
    you really implemented Singleton because "There Can
    Only BE One", I'd say prohibiting subclassing and
    cloning might be important.
    I gotta go with the OP on this. That comment is abit queer.
    I gotta go with the definition of Singleton on this
    and disagree. It's not like it's that difficult.
    Don't implement Cloneable or Serializable and make
    the constructors private. Done. What's the
    problem?
    At some point it is just too much.
    Are you going to implement a security manager as well? Because unless you do I can create JNI method and create a new object as well.
    If they don't understand that the singleton is a singleton then are you going to assume that that is the only problem that they are having?
    When I program I make assumptions about those that I work with and those that will come after me. I like to think that they have a minimal level of intelligent. They might not write the best code all the time but they do understand most of the ideas. And given that singleton the most used and probably easiest pattern to understand is it really necessary to be so protective?

  • Singleton pattern class and static class

    Hi,
    what is difference between the singleton pattern class and static class ?
    in singleton pattern, we declare a static member[which hold one value at a time] ,static method[ which return static member value] and a private constructor[not allow to direct instantiation]. My words are -- as a singleton pattern we implement static class .
    so can we say a singleton pattern is static class it means both are same or is any difference between these two ??

    malcolmmc wrote:
    On several occasions I've had to convert a static (never instanceated) class to a singleton type, for example because I realise I need an instance per thread, or I decide to make a program more modular, with more than one configuration.
    I've never done the opposite.
    So generally I favour the singleton if there any "state" involved, because it's more flexible in unanticipated directions. It also gives extra flexibility when building tests, especially if you program to an interface.Total agreement; if anything it is dead hard to override static method logic with mock code in unit tests (I had to do it by keeping the static methods in place but making them internally use a singleton instance of itself of which the instance variable could be overwritten with a mock implementation for unit testing purposes...).
    'Static classes' and/or methods are great for very simple util functions, but I wouldn't use them for anything other than that.

  • Singleton pattern, scheduled receive location and suspended orchestrations

    Hello,
    In our project we have several orchestrations that are triggered every minute with the Scheduler Adapter (business requirement is near real-time).
    Each of these orchestration must have only 1 instance running at the same time, so we have implemented the singleton pattern. We followed a design like this one: https://fehlberg.wordpress.com/2008/06/06/biztalk-singleton-orchestration-design/
    But we end up having suspended orchestrations with the error "The instance completed without consuming all of its messages. The instance and its unconsumed messages have been suspended."
    I know it's a risk with this pattern. I thought it would happen only when the instance would run in more than 1 min (because the scheduler adapter is sending a file every minute).
    But it happens even with some instances running in about 15sec, so there is something I don't understand, here is an example:
    Here we can see that the TransferRegion orchestration started at 10:26:00 (which is expected) and failed.
    When I open the orchestration debugger, the time is different, the orchestration is shown starting at 10:26:44 (44 sec later):
    And the orchestration ended at 10:27:00:453.
    The message not consumed that caused the error has been triggered at 10:27:00.
    So I understand that the message arrived just after the listen shape but before the orchestration ends, but I don't understand why the orchestration started 44 sec after is was supposed to ...
    Any idea? I'm kind of clueless for now ...

    So, are these 8 Orchestrations actually processing messages or are they doing some other work every minute or so?
    If they're not processing actual messages, maybe a Windows Service or job scheduled by the SQL Agent or Windows Scheduler would be more...appropriate.  We all love BizTalk, but some parts of the stack do some things better.
    If they are processing messages or doing some genuine BPI type work, calling services, transformations etc., then maybe a Singleton+Scheduled Task is not the best solution.
    I'm assuming the actual requirement is the process must run with no less than 1 minute between executions, but if an execution takes >1 min, don't overlap.  An internal 1 min timer would probably work very well, but you still have the problem of
    activating and deactivating the Orchestration.  You'd basically have to build some control infrastructure similar to the EDI Batching Service.
    Here's a completely different suggestion:
    SQL Table that maintains the state of each process, say Active or Complete.
    Poll every 15 seconds a Stored Procedure that tests the status and returns an activation message when that process shows Complete.  It would flip it to Active at the same time.
    Orchestration runs and the last shape sends a message to change the status to Complete.
    Rinse Repeat.  No long running Orchestrations, Singletons, Correlations, etc...
    Hi John,
    We have 8 independent orchestrations. Each of them is triggered by different scheduled receive location.
    The orchestrations then process messages (calling stored procedures, mapping and calling web services).
    You are right for the requirement. I tried to deactivate the receive location at the beginning of the process and restart it at the end, but I ran into some weird errors on the SSO DB and others like "Could not retrieve transport type data for Receive
    Location 'Trigger_xxxxx_SCHEDULE' from config store. The transaction associated with the current connection has completed but has not been disposed.  The transaction must be disposed before the connection can be used to execute SQL statements."
    Thanks for the new design suggestion, I will see the effort required and if the client approves it ;)

  • How we can limit the number of concurrent calls to a WCF service without use the Singleton pattern or without do the change in BizTalk Configuration file?

    How can we send only one message to a WCF service at a time? How we can limit the number of concurrent calls to a WCF service without use the Singleton pattern or without do the change in BizTalk Configuration file? Can we do it by Host throttling?

    Hi Pawan,
    You need to use WCF-Custom adapter and add the ServiceThrottlingBehavior service behavior to a WCF-Custom Locations.
    ServiceThrottlingBehavior.MaxConcurrentCalls - Gets or sets a value that specifies the maximum number of messages actively processing across a ServiceHost. The MaxConcurrentCalls property specifies the maximum number of messages actively
    processing across a ServiceHost object. Each channel can have one pending message that does not count against the value of MaxConcurrentCalls until WCF begins to process it.
    Follow MSDN-
    http://msdn.microsoft.com/en-us/library/ee377035%28BTS.10%29.aspx
    http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicethrottlingbehavior.maxconcurrentcalls.aspx
    I hope this helps.
    Rachit
    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

  • How to implement Strategy pattern in ABAP Objects?

    Hello,
    I have a problem where I need to implement different algorithms, depending on the type of input. Example: I have to calculate a Present Value, sometimes with payments in advance, sometimes payment in arrear.
    From documentation and to enhance my ABAP Objects skills, I would like to implement the strategy pattern. It sounds the right solution for the problem.
    Hence I need some help in implementing this pattern in OO. I have some basic OO skills, but still learning.
    Has somebody already implemented this pattern in ABAP OO and can give me some input. Or is there any documentation how to implement it?
    Thanks and regards,
    Tapio

    Keshav has already outlined required logic, so let me fulfill his answer with a snippet
    An Interface
    INTERFACE lif_payment.
      METHODS pay CHANGING c_val TYPE p.
    ENDINTERFACE.
    Payment implementations
    CLASS lcl_payment_1 DEFINITION.
      PUBLIC SECTION.
      INTERFACES lif_payment.
      ALIASES pay for lif_payment~pay.
    ENDCLASS.                 
    CLASS lcl_payment_2 DEFINITION.
      PUBLIC SECTION.
      INTERFACES lif_payment.
      ALIASES pay for lif_payment~pay.
    ENDCLASS.                   
    CLASS lcl_payment_1 IMPLEMENTATION.
      METHOD pay.
        "do something with c_val i.e.
        c_val = c_val - 10.
      ENDMETHOD.                   
    ENDCLASS.                  
    CLASS lcl_payment_2 IMPLEMENTATION.
      METHOD pay.
        "do something else with c_val i.e.
        c_val = c_val + 10.
      ENDMETHOD.  
    Main class which uses strategy pattern
    CLASS lcl_main DEFINITION.
      PUBLIC SECTION.
        "during main object creation you pass which payment you want to use for this object
        METHODS constructor IMPORTING ir_payment TYPE REF TO lif_payment.
        "later on you can change this dynamicaly
        METHODS set_payment IMPORTING ir_payment TYPE REF TO lif_payment.
        METHODS show_payment_val.
        METHODS pay.
      PRIVATE SECTION.
        DATA payment_value TYPE p.
        "reference to your interface whcih you will be working with
        "polimorphically
        DATA mr_payment TYPE REF TO lif_payment.
    ENDCLASS.                  
    CLASS lcl_main IMPLEMENTATION.
      METHOD constructor.
        IF ir_payment IS BOUND.
          me->mr_payment = ir_payment.
        ENDIF.
      ENDMETHOD.                  
      METHOD set_payment.
        IF ir_payment IS BOUND.
          me->mr_payment = ir_payment.
        ENDIF.
      ENDMETHOD.                  
      METHOD show_payment_val.
        WRITE /: 'Payment value is now ', me->payment_value.
      ENDMETHOD.                  
      "hide fact that you are using composition to access pay method
      METHOD pay.
        mr_payment->pay( CHANGING c_val = payment_value ).
      ENDMETHOD.                   ENDCLASS.                  
    Client application
    PARAMETERS pa_pay TYPE c. "1 - first payment, 2 - second
    DATA gr_main TYPE REF TO lcl_main.
    DATA gr_payment TYPE REF TO lif_payment.
    START-OF-SELECTION.
      "client application (which uses stategy pattern)
      CASE pa_pay.
        WHEN 1.
          "create first type of payment
          CREATE OBJECT gr_payment TYPE lcl_payment_1.
        WHEN 2.
          "create second type of payment
          CREATE OBJECT gr_payment TYPE lcl_payment_2.
      ENDCASE.
      "pass payment type to main object
      CREATE OBJECT gr_main
        EXPORTING
          ir_payment = gr_payment.
      gr_main->show_payment_val( ).
      "now client doesn't know which object it is working with
      gr_main->pay( ).
      gr_main->show_payment_val( ).
      "you can also use set_payment method to set payment type dynamically
      "client would see no change
      if pa_pay = 1.
        "now create different payment to set it dynamically
        CREATE OBJECT gr_payment TYPE lcl_payment_2.
        gr_main->set_payment( gr_payment ).
        gr_main->pay( ).
        gr_main->show_payment_val( ).
      endif.
    Regads
    Marcin

  • Implementing DAO Pattern in ABAP

    This discussion implement DAO pattern asked the question of how to develop a DAO pattern in ABAP but i'd like to go a little deeper.
    The only answer given suggested the following design pattern:
    I don't have an coded example here, but isn't it sufficient for this pattern  to build an interface with some get- and set-methods? This interface can be implemented by several classes with different data retrieval logic. Then a static factory-method could do the job to decide during runtime which actual class is instantiated, returning the interface.
    Can anyone give an abstract description of this implementation relative to an SAP module (How would one approach this implementation in MM, PM, FICO, HR)
    Can anyone see any issues in this design?
    Can anyone provide an alternate design?
    Are we missing any steps?
    Together we can build a solid abap DAO everyone can use.

    I started to read about DAO pattern some days ago and found this great blog post:
    ABAP Unit Tests without database dependency - DAO concept
    I am starting to implement unit test in my developments and DAO pattern seems to be a clever choice.
    Regards,
    Felipe

  • Best Practice:  Using a static variables and methods vs singleton pattern

    Just curious, since when anything, within a class, is denoted as static it typically will be stored in main memory as a class property(method, variables, etc). Is it a good practice to be doing this all the time or is the singleton pattern a better choice. Please explain why. Thanks.

    I wouldnot make anything other than the constants and the instance itself static. And I cant think of a reason wjy one would.

  • How to implement Observer Pattern?

    Hello guys,
    I have some problems with implementing the observer pattern. So i m making an sound application and i need to put a meter changing with the volume.
    I have already the meter designed and the volume is calculated.
    So i have a class called Application (is the main class) and this class have the graphic designer from the application, makes the audio capture and calculate the volume.
    And i have the MeterMic class and in this class i have the graphic Meter where i send this graphic meter to the application via JPanel.
    In MeterMic i have the variable "value" and this variable will make the changes in the bars of the meter and i want to equal the value to the volume from the application. I try referencing by the Application object but doesnt pass the value from the volume.
    So i would like to implement the Observer pattern.
    I need to observ the variable volume and than the volume have changes i want to send that change to variable value in MeterMic.
    My problem is: who is the observer and observ? And what i need to do to implement the pattern.
    My best,
    David

    Kayaman wrote:
    DavidHenriques wrote:
    So i just need to implement the observers interfaces and than implement the method update and notify in the classes.You should probably forget the Observer/Observable classes, they're Java 1.0 stuffDo you think they are usless just because they are old?
    so you don't have to or need to use them, even though the names sound appealing.I still like them because the Observable saves me from repetitively implementing (hopefully thread save) method for notifying the observers...
    It's basically the same thing, you just see a lot more talk about Events/Listeners than Observers/Observables these days.The good thing on Events/Listeners is that they are type save which is an importand feature.
    But I like to build them on top of Observer/Observable on the event source side.
    bye
    TPD

Maybe you are looking for

  • W540 + Ultra docks = big serious issue

    Hello everyone, We recently ordered 30+ x240s and w540 laptops using the ultradocks. Here's the prequel 1. initially they had the issue with monitors going blank, that has been fixed with a firmware update 2. there was a second firmware update ver 2.

  • Mod_weblogic and load balancing algorithm

    Hi, we have a problem where we have 2 boxes, each with Apache (doing some header and url rewrites) and configured with mod_weblogic, and weblogic servers with our stateless applications. We have a HW loadbalancer in front, doing round-robin balancing

  • ALV Scope of List but not ZME55

    Our Technical team Created a Z Tranx copying ME55. ME55 was executing successfully in ALV Scope of List but not ZME55. Error: Scope of list ALV not defined (please correct) Any suggestions. Is it a functional issue or a technical one? Thanks in advan

  • SCM EWM and ERP Connectivity issue

    Hi, I am getting the below error message when I check the configutation of ERP - SM EWM.Please do the need full Logical system is missing for business system CSSCMDEV_230 (ERP System) Message no. /SCWM/EEC_CHECK011 Regards Govind

  • Blocking iMessages in Mavericks OS?

    Can I block iMessages from a specific person with Mavericks operating system?