Search Results

Search found 774 results on 31 pages for 'm singleton'.

Page 11/31 | < Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >

  • Migration solution for singletons in an OSGI environment

    - by Ido
    I'm working in a JEE Environment in which each application is in a war file of its own. In the WEB-INF/lib of each application war file there is a common jar that is shared by all applications. This common jar contains several Singletons which are accessed from many points in the code. Because of the war-file boundaries each application has its own instances of the Singletons. Which is how we operate today, since we want to configure some of the singletons differently in each application. Now we are moving towards an OSGi environment, where this solution will no longer work since each bundle has its own class loader, so if I try to access MySingleton which resides in bundle "common.jar" from bundle "appA.jar" or from bundle "appB.jar" I will get the same instance. Remember I "want" a different instance of a singleton per bundle. (as ironic as it sounds) Now I realize the ideal solution would be to fix the code to not rely on those singletons, however due to a tight schedule I was wondering if you guys can suggest some sort of a migration solution that would allow me to use bundle-wide singletons so each of them could be configured per bundle.

    Read the article

  • nhibernate sessionfactory instance more than once on web service

    - by Manuel
    Hello, i have a web service that use nhibernate. I have a singleton pattern on the repositorry library but on each call the service, it creates a new instance of the session factory wich is very expensive. What can i do? region Atributos /// <summary> /// Session /// </summary> private ISession miSession; /// <summary> /// Session Factory /// </summary> private ISessionFactory miSessionFactory; private Configuration miConfiguration = new Configuration(); private static readonly ILog log = LogManager.GetLogger(typeof(NHibernatePersistencia).Name); private static IRepositorio Repositorio; #endregion #region Constructor private NHibernatePersistencia() { //miConfiguration.Configure("hibernate.cfg.xml"); try { miConfiguration.Configure(); this.miSessionFactory = miConfiguration.BuildSessionFactory(); this.miSession = this.SessionFactory.OpenSession(); log.Debug("Se carga NHibernate"); } catch (Exception ex) { log.Error("No se pudo cargar Nhibernate " + ex.Message); throw ex; } } public static IRepositorio Instancia { get { if (Repositorio == null) { Repositorio = new NHibernatePersistencia(); } return Repositorio; } } #endregion #region Propiedades /// <summary> /// Sesion de NHibernate /// </summary> public ISession Session { get { return miSession.SessionFactory.GetCurrentSession(); } } /// <summary> /// Sesion de NHibernate /// </summary> public ISessionFactory SessionFactory { get { return this.miSessionFactory; } } #endregion In wich way can i create a single instance for all services?

    Read the article

  • how to create a system-wide independent universal counter object primarily for Database keys?

    - by andora
    I would like to create/use a system-wide independent universal 'counter object' that can be called via COM in a thread-safe manner. The counter object will be passed an ID to identify which counter to return, handle the counting, 'persist' the count (occasionally), have reasonable performance (as fast as possible) perhaps capable of 1000 counts per second or better (1mS) and be accessible cross-process/out-of-process. The current count status must be persisted between object restarts/shutdowns. The counter object is liklely to be a 'singleton' type object implemented in some form of free-threaded dictionary, containing maybe 10 counters (perhaps 50 max). The count needs to be monotonic and consistent, (ie: guaranteed unique sequential values). Each counter should have a few methods, like reset, inc, dec, set, clear, remove. As a luxury, I would like to have a variable-increment (ie: 'step by' value). To support thread-safefty, perhaps some sorm of critical-section or mutex call. It just needs to return a long/4byte signed integer. I really want something that can be called from anywhere, including VBScript, so I figure COM is my preferred solution. The primary use of this is for database keys. I am unable to use autoinc or guid type keys and have ruled out database-generated counting systems at this point. I've spent days researching this and I have really struggled to find a solution. The best I can find is a free-threaded dictionary object that can be instantiated using COM+ from Motobit - it seems to offer all the 'basics' and I guess I could create some form of wrapper for this. So, here are my questions: Does such a 'general purpose counter-object already exist? Can you direct me to it? (MS did do an IIS/ASP object called 'MSWC.Counter' but this isn't 'cross-process'/ out-of-process component and isn't thread-safe. (but if it was, it would do!) What is the best way of creating such a Component? (I'd prefer VB6 right-now, [don't ask!] but can do in VB.NET2005 if I had to). I don't have the skills/knowledge/tools to use anything else. I am desparate for a workable solution. I need specific guidance! If anybody can code something up for me I am prepared to pay for it.

    Read the article

  • Unity Register two interfaces as one singleton

    - by Christian
    Hi all, how do I register two different interfaces in Unity with the same instance... Currently I am using _container.RegisterType<EventService, EventService>(new ContainerControlledLifetimeManager()); _container.RegisterInstance<IEventService>(_container.Resolve<EventService>()); _container.RegisterInstance<IEventServiceInformation>(_container.Resolve<EventService>()); which works, but does not look nice.. So, I think you get the idea. EventService implements two interfaces, I want a reference to the same object if I resolve the interfaces. Chris

    Read the article

  • Singleton Pattern combine with a Decorator

    - by Mike
    Attached is a classic Decorator pattern. My question is how would you modify the below code so that you can wrap zero or one of each topping on to the Pizza Right now I can have a Pepporini - Sausage -- Pepporini -- Pizza class driving the total cost up to $10, charging twice for Pepporini. I don't think I want to use the Chain of Responsibility pattern as order does not matter and not all toppings are used? Thank you namespace PizzaDecorator { public interface IPizza { double CalculateCost(); } public class Pizza: IPizza { public Pizza() { } public double CalculateCost() { return 8.00; } } public abstract class Topping : IPizza { protected IPizza _pizzaItem; public Topping(IPizza pizzaItem) { this._pizzaItem = pizzaItem; } public abstract double CalculateCost(); } public class Pepporini : Topping { public Pepporini(IPizza pizzaItem) : base(pizzaItem) { } public override double CalculateCost() { return this._pizzaItem.CalculateCost() + 0.50; } } public class Sausage : Topping { public Sausage(IPizza pizzaItem) : base(pizzaItem) { } public override double CalculateCost() { return this._pizzaItem.CalculateCost() + 1.00; } } public class Onions : Topping { public Onions(IPizza pizzaItem) : base(pizzaItem) { } public override double CalculateCost() { return this._pizzaItem.CalculateCost() + .25; } } }

    Read the article

  • How to keep alive an HttpModule (a.k.a register it as a singleton)

    - by Micah
    I pretty sure I've seen this somewhere but I can't seem to find it anywhere. I have an HttpModule that can be used across multiple requests. In other words instead of creating a new instance of the Module on every request it only ever needs to create it once. Does this ring a bell to anyone? If so, what's the method for configuring to work this way?

    Read the article

  • how to make application singleton.

    - by Mohsan
    hi. i want to make sure that only one instance of application run... i added the mutex check but it causes problem in 64 bit system. the second way is to search process table.. This check can be easily defeated by renaming application. please tell me how to make sure that only one instance of application run.

    Read the article

  • Does this singleton pattern make sense?

    - by dontWatchMyProfile
    @implementation MySingletonClass static MySingletonClass *sharedInstance = nil; + (MySingletonClass*)sharedInstance { @synchronized(self) { if (sharedInstance == nil) { sharedInstance = [[self alloc] init]; } } return sharedInstance; } + (id)alloc { @synchronized(self) { if (sharedInstance == nil) { sharedInstance = [super alloc]; return sharedInstance; } } return nil; } + (id)allocWithZone:(NSZone *)zone { @synchronized(self) { if (sharedInstance == nil) { sharedInstance = [super allocWithZone:zone]; return sharedInstance; } } return nil; } -(id)init { self = [super init]; if (self != nil) { // initialize stuff here } return self; } @end Not sure if it's ok to overwrite both alloc and allocWithZone: like this...?

    Read the article

  • Singleton Creation preference

    - by cwieland
    You can create singletons in a variety of ways. I am wondering which is better between these. +(ServerConnection*)shared{ static dispatch_once_t pred=0; __strong static id _sharedObject = nil; dispatch_once(&pred, ^{ _sharedObject = [[self alloc] init]; // or some other init method }); return _sharedObject; } I could see that this compiles down to something very fast. I would think that checking the predicate would be another function call. The other is: +(ServerConnection*)shared{ static ServerConnection* connection=nil; if (connection==nil) { connection=[[ServerConnection alloc] init]; } return connection; } Are there any major differences between the two? I know these are probably similar enough to not worry about it. But Just wondering.

    Read the article

  • How to optimise Andengine's PathModifer (with singleton or pool)?

    - by Casla
    I am trying to build a game where the character find and follows a new path when a new destination is issued by the player, kinda like how units in RTS games work. This is done on a TMX map and I am using the A Star path finder utilities in Andengine to do this.David helped me on that: How can I change the path a sprite is following in real time? At the moment, every-time a new path is issued, I have to abandon the existing PathModifer and Path instances, and create new ones, and from what I read so far, creating new objects when you could re-use existing ones are a big waste for mobile applications. This is how I coded it at the moment: private void loadPathFound() { if (mAStarPath != null) { modifierPath = new org.andengine.entity.modifier.PathModifier.Path(mAStarPath.getLength()); /* replace the first node in the path as the player's current position */ modifierPath.to(player.convertLocalToSceneCoordinates(12, 31)[Constants.VERTEX_INDEX_X]-12, player.convertLocalToSceneCoordinates(12, 31)[Constants.VERTEX_INDEX_Y]-31); for (int i=1; i<mAStarPath.getLength(); i++) { modifierPath.to(mAStarPath.getX(i)*TILE_WIDTH, mAStarPath.getY(i)*TILE_HEIGHT); /* passing in the duration depended on the length of the path, so that the animation has a constant duration for every step */ player.registerEntityModifier(new PathModifier(modifierPath.getLength()/100, modifierPath, null, mIPathModifierListener)); } } The ideal implementation will be to always have just one object of PathModifer and just reset the destination of the path. But I don't know how you can apply the singleton patther on Andengine's PathModifer, there is no method to reset attribute of the path nor the pathModifer. So without re-write the PathModifer and the Path class, or use reflection, is there any other way to implement singleton PathModifer? Thanks for your help.

    Read the article

  • Builder pattern and singletons

    - by Berryl
    Does anyone have any links to some code they like that shows a good example of this in c#? As an example of bad code, here is what a builder I have now looks like. I'm trying to have a way to keep the flexibility of the builder pattern but not rebuild the properties. Cheers, Berryl public abstract class ActivityBuilder { public abstract ActivityBuilder Build(); public bool IsBuilt { get; protected set; } public IEnumerable<Project> Projects { get { if(_projects==null) { Build(); } return _projects; } } protected IEnumerable<Project> _projects; // .. other properties }

    Read the article

  • Add multiple entities to Javascript namespace from different files

    - by Brian M. Hunt
    Given a namespaces ns used in two different files: abc.js ns = ns || (function () { foo = function() { ... }; return { abc : foo }; }()); def.js // is this correct? ns = ns || {} ns.def = ns.def || (function () { defoo = function () { ... }; return { deFoo: defoo }; }()); Is this the proper way to add def to the ns to a namespace? In other words, how does one merge two contributions to a namespace in javascript? If abc.js comes before def.js I'd expect this to work. If def.js comes before abc.js I'd expect ns.abc to not exist because ns is defined at the time. It seems there ought to be a design pattern to eliminate any uncertainty of doing inclusions with the javascript namespace pattern. I'd appreciate thoughts and input on how best to go about this sort of 'inclusion'. Thanks for reading. Brian

    Read the article

  • Static variables in Java for a test oObject creator

    - by stevebot
    Hey, I have something like the following TestObjectCreator{ private static Person person; private static Company company; static { person = new Person() person.setName("Joe"); company = new Company(); company.setName("Apple"); } public Person createTestPerson(){ return person; } public Person createTestCompany(){ return company; } } By applying static{} what am I gaining? I assume the objects are singletons as a result. However, if I did the following: Person person = TestObjectCreator.createTestPerson(); person.setName("Jill"); Person person2 = TestObjectCreator.createTestPerson(); would person2 be named Jill or Joe?

    Read the article

  • using Mutex causing application to hang on Win XP X64

    - by Mohsan
    hi. I used the following code to verify the single instance of application. On Win XP X86 it is working fine, but on X64 after 3 to 4 minutes System generates StackOverflowException and causes the application to hang. after removing this check application is working fine.. Please tell me what should be the reason. code is static void Main() { bool instanceCountOne = false; using (Mutex mtex = new Mutex(true, "AppName", out instanceCountOne)) { if (instanceCountOne) { #if (DEBUG) RunInDebugMode(); #else RunInReleaseMode(); #endif mtex.ReleaseMutex(); } else { MessageBox.Show( "An application instance is already running", "App Name", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } it crashes when single instance of application is running.

    Read the article

  • Is it bad practice to have state in a static class?

    - by Matthew
    I would like to do something like this: public class Foo { // Probably really a Guid, but I'm using a string here for simplicity's sake. string Id { get; set; } int Data { get; set; } public Foo (int data) { ... } ... } public static class FooManager { Dictionary<string, Foo> foos = new Dictionary<string, Foo> (); public static Foo Get (string id) { return foos [id]; } public static Foo Add (int data) { Foo foo = new Foo (data); foos.Add (foo.Id, foo); return foo; } public static bool Remove (string id) { return foos.Remove (id); } ... // Other members, perhaps events for when Foos are added or removed, etc. } This would allow me to manage the global collection of Foos from anywhere. However, I've been told that static classes should always be stateless--you shouldn't use them to store global data. Global data in general seems to be frowned upon. If I shouldn't use a static class, what is the right way to approach this problem? Note: I did find a similar question, but the answer given doesn't really apply in my case.

    Read the article

  • How to use application config file in C#?

    - by badpanda
    I am trying to use a config file in my C# console application. I created the file within the project by going New -- Application Configuration File, and naming it myProjectName.config. My config file looks like this: <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="SSDirectory" value="D:\Documents and Settings\****\MyDocuments\****" /> </appSettings> </configuration> The code to access it looks like this: private FileValidateUtil() { sSDirFilePath = ConfigurationSettings.AppSettings["SSDirectory"]; if (sSDirFilePath == null) Console.WriteLine("config file not reading in."); } Can anyone lend a hint as to why this is not working? (I am getting the error message.) Thanks!! badPanda

    Read the article

  • Singelton on iPhone Simulator vs Singelton on real Device

    - by Helge Becker
    I am using a Singelton for some shared stuff. In the simulator, the app crashes ocasionally. Tracking the crash down shows that the the properties of my Singelton became dealocated. Those crashes never happend on a real device. Does the iPHone simulator handle memory managemend different? GC maybe? Changed the singelton to match this pattern. The iPhone Simulator dont crash now, but I am not sure about the memory handling on the real device. I assume that this solution will cause problems. What do you think?

    Read the article

  • dao as a member of a servlet - normal?

    - by EugeneP
    I guess, DAO is thread safe, does not use any class members. So can it be used without any problem as a private field of a Servlet ? We need only one copy, and multiple threads can access it simultaneously, so why bother creating a local variable, right?

    Read the article

< Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >