Posts for the month of December 2006

No Static Method in Interface, So I Write Code As ...

Java does not support static method in interface. But sometimes, I just want a static method to say: PersistenceManager.getDefault(), where PersistenceManager is going to be an interface. I don't like to add one more class named PersistenceManagerFactory, with a method:

public static PersistenceManager PersistenceManagerFactory.getDefault()

So I write code like:

public class PersistenceManager {
    private static I i;

    public static I getDefault() {
        return i == null ? i = ServiceLoader.load(I.class).iterator().next() : i;
    }
    
    /** The interface I, which is actually the PersistenceManager should be: */
    public static interface I {
        
        void saveQuotes(String symbol, Frequency freq, List quotes);
        List restoreQuotes(String symbol, Frequency freq);
        void deleteQuotes(String symbol, Frequency freq, long fromTime);
        void dropAllQuoteTables(String symbol);
        
        void shutdown();
        
        QuotePool getQuotePool();
        TickerPool getTickerPool();
    }
    
}

Then implement the PersistenceManager.I in another package, like:

public class NetBeansPersistenceManager implements PersistenceManager.I {
   ...
}

And declare it under the META-INF as:

core/src/META-INF/services/org.aiotrade.math.PersistenceManager$I

which contains one line:

org.aiotrade.platform.core.netbeans.NetBeansPersistenceManager

I can call PersistenceManager.getDefault().showdown() now.

The Design of AIOTrade (Part I)

There are no design documents of AIOTrade released so far, it's because I'm still not satisfied the code and architecture, anyway, I'll try to post some draft overall views of the design in my blog.

Below is a digram of main classes [updated: Dec 10, 2006]:

Click on the picture to enlarge it

main classes