無料で使えるシステムトレードフレームワーク「Jiji」 をリリースしました!

・OANDA Trade APIを利用した、オープンソースのシステムトレードフレームワークです。
・自分だけの取引アルゴリズムで、誰でも、いますぐ、かんたんに、自動取引を開始できます。

GAEでもGoogle GuiceのAOPは使えます。

Google App Engine上でも普通に使えましたよ > Google GuiceAOP。ということで、動作確認に使った簡単なサーブレットを公開してみます。

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.matcher.Matchers;

/**
 * インターセプターを使うサーブレット
 */
@SuppressWarnings("serial")
public class InterceptorTestServlet extends HttpServlet {
    
    /**
     *  GETメソッドを処理する。
     */
    public void doGet( final HttpServletRequest req, final HttpServletResponse resp)
            throws IOException {
        resp.setContentType("text/plain");
        
        // インターセプターを作成
        final MethodInterceptor interceptor = new MethodInterceptor() {
            @Override public Object invoke(MethodInvocation mi) 
            throws Throwable {
                try {
                    resp.getWriter().write("before."); 
                    return mi.proceed();
                } finally {
                    resp.getWriter().write("after."); 
                }
            }
        };
        
        // コンテナを作成/アスペクト適用済みインスタンスを取得
        Foo aspected = Guice.createInjector(new AbstractModule() {
            @Override protected void configure() {
                bind( Foo.class );
                bindInterceptor(Matchers.any(), Matchers.any(), interceptor);
            }
        }).getInstance( Foo.class );
        
        // メソッドを実行。
        try {
            aspected.call( resp );
        } catch (Exception e) {
            throw new IOException(e); 
        }        
    }
    // テスト用クラス
    static class Foo {
        public void call( HttpServletResponse resp )throws Exception {
            resp.getWriter().write("foo."); 
        }
    }
}

実行結果はこちら