8月 022012
 

原因よく分からないけどメモ。

Unable to start the daemon process.

This problem might be caused by incorrect configuration of the daemon.

For example, an unrecognized jvm option is used.

Please refer to the user guide chapter on the daemon at http://gradle.org/docs/current/userguide/gradle_daemon.html

Please read below process output to find out more:

———————–

Error occurred during initialization of VM

Could not reserve enough space for object heap

Error: Could not create the Java Virtual Machine.

Error: A fatal exception has occurred. Program will exit.

  • daemonじゃなければちゃんと動く。
  • JDK7u5だとダメ
  • JDK6u33だとOK
7月 182012
 

Primavera Integration API Programmer’s Reference には

Of course, Local Mode could be called directly from JSP pages that are deployed as part of a Web Application.

という記述があるが、LocalModeでリモートDBにアクセスすると以下のようなエラーとなる。

java.lang.RuntimeException: com.primavera.bo.common.InvalidInstanceLoginException: Invalid database instance while checking authentication mode.
        at j0a1590.Main.testPrimavera(Main.java:72)
        at j0a1590.Main.main(Main.java:26)
Caused by: com.primavera.bo.common.InvalidInstanceLoginException: Invalid database instance while checking authentication mode.
        at com.primavera.bo.common.b.a(LoginHelper.java:111)
        at com.primavera.bo.remotable.SessionLifetime.login(SessionLifetime.java:57)
        at com.primavera.bo.remotable.qproxy.SessionLifetime.login(SessionLifetime.java:76)
        at com.primavera.bo.DBSessionLifetime.login(DBSessionLifetime.java:28)
        at com.primavera.integration.server.ServerFacadeBase.login(ServerFacadeBase.java:434)
        at com.primavera.integration.server.ServerFacade.login(ServerFacade.java:11)
        at com.primavera.integration.client.LocalSession.login(LocalSession.java:90)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.primavera.integration.client.Session.a(Session.java:355)
        at com.primavera.integration.client.Session.login(Session.java:343)
        at j0a1590.Main.testPrimavera(Main.java:60)
        ... 1 more

アプリケーションサーバーとDBサーバーが同じマシンの場合は可能。

マニュアル通り、以下のような変更を施せばRemoteModeに変更出来る。
ただしサーバーでRMIサービスが提供されている必要がある。
[java title=”LocalMode”]
DatabaseInstance[] dbInstances = Session.getDatabaseInstances( RMIURL.getRmiUrl( RMIURL.LOCAL_SERVICE ) );
// Assume only one database instance for now, and hardcode the username and
// password for this sample code
session = Session.login( RMIURL.getRmiUrl( RMIURL.LOCAL_SERVICE ), dbInstances[0].getDatabaseId(), “admin”, “admin” )
[/java]
[java title=”RemoteMode”]
DatabaseInstance[] dbInstances = Session.getDatabaseInstances( RMIURL.getRmiUrl( RMIURL.STANDARD_RMI_SERVICE, “localhost”, 9099 ) );
// Assume only one database instance for now, and hardcode the username and
// password for this sample code. Assume the server is local for this sample code.
session = Session.login( RMIURL.getRmiUrl( RMIURL.STANDARD_RMI_SERVICE, “localhost”, 9099 ), dbInstances[0].getDatabaseId(), “admin”, “admin” );
[/java]

サーバーは9099でListeningしているが、実際にデータ通信を行う際は新たなTCPコネクションを形成するようで、そちらのポートが62793であるが、恐らくは(同時アクセスの場合などで)クライアントによって変更される可能性があると考えられる。

ちなみにJavaRMIレジストリーの標準ポートは1099の模様。
Primaveraは9099がデフォの様子。
レジストリポートはAdministrator toolで変更可能。

7月 182012
 
[raw mark=”1,17″]
C:\example\>keytool -genkey -alias ssltest -keyalg RSA -keysize 512 -keypass password -validity 3650 -storetype JKS -keystore server_keystore -storepass password
姓名を入力してください。
[Unknown]: hostname
組織単位名を入力してください。
[Unknown]: ou
組織名を入力してください。
[Unknown]: o
都市名または地域名を入力してください。
[Unknown]: Japan
州名または地方名を入力してください。
[Unknown]: Tokyo
この単位に該当する 2 文字の国番号を入力してください。
[Unknown]: JP
CN=hostname, OU=ou, O=o, L=Japan, ST=Tokyo, C=JP でよろしいですか?
[no]: yes

C:\example\>keytool -selfcert -alias ssltest -validity 3650 -keystore server_keystore
[/raw]

7月 182012
 

JKSキーストアを事前に用意し、JavaオプションにhttpsPorthttpsKeyStorehttpsKeyStorePasswordを指定すれば良い。

[xml title=”jenkins.xml”]
-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar “%BASE%\jenkins.war” –httpPort=8080 –httpsPort=8081 –httpsKeyStore=d:\example\server_keystore –httpsKeyStorePassword=password
[/xml]

これでhttps://localhost:8081/でHTTPSアクセスできる。

7月 172012
 

バグっぽい。

[java title=”org.webcurator.core.store.CrawlLogIndexer抜粋” mark=”10″]
@Override
public void indexFiles(Long harvestResultOid) throws ServiceException {

// sort the crawl.log file to create a sortedcrawl.log file in the same
// directory.
log.info(“Generating ” + sortedLogFileName + ” file for ” + getResult().getTargetInstanceOid());

// create path to log files folder from input directory..
String logPath = directory.getAbsolutePath().substring(0, directory.getAbsolutePath().length()-1);
logPath = logPath + logsSubFolder + “\\”;

// write new ‘stripped’ crawl.log, replacing multiple spaces with a single space in each record..
try {
[/java]

セパレータとしてバックスラッシュを使用しているが、これではWindows環境でしかセパレータとして認識しない。
本来はFile.separator()かFile.separatorChar()で取得すべきである。
これのせいで正常にログ処理ができていないと考えられる。

7月 132012
 

FileStore→LocationDB→ResourceIndexと言った具合にマージされる。

Wayback – Resource Store Configuration

デフォルトではResourceIndexにはBarkleyDB Java Edition(BDB)を利用している。
これを編集するのはやや骨が折れる。

WaybackのAPI(libフォルダ内jar)を利用する事で削除可能。

  1. ArcIndexerを使用してarcファイルからCaptureSerchResultを抽出
  2. CaptureSerchResultをBDBRecourdに変換し、Keyを取得
  3. BDBRecordSetを使用し、Indexを削除
[java title=”例 ※トランザクションは構成していない”]
BDBRecordSet rs = new BDBRecordSet();
try{
rs.initializeDB(“D:\\DL\\wct\\bdb”, “DB1”);
//System.out.println(rs.get(“example.com/css/disastercenter.css 20111108054107 1314431 20111108054041-00000.ver1.arc”));

CloseableIterator itr = new ArcIndexer().iterator(“D:\\DL\\wct\\20111128074440-00000.ver1.arc”);
UrlCanonicalizer canonicalizer = new AggressiveUrlCanonicalizer();
SearchResultToBDBRecordAdapter adapter = new SearchResultToBDBRecordAdapter(canonicalizer);
while(itr.hasNext()){
CaptureSearchResult result = itr.next();
BDBRecord r = adapter.adapt(result);
System.out.println(BDBRecordSet.bytesToString(r.getKey().getData()));

rs.delete(BDBRecordSet.bytesToString(r.getKey().getData()));
}
}catch(Throwable t){
t.printStackTrace();
}finally{
rs.shutdownDB();
}
[/java]

7月 132012
 

らしい。
要するに定数の値を変更しても、それを参照してる側も再コンパイルしないと値が反映されない。
共通ライブラリに定数を定義し、他のプログラムで参照している場合などがヤバイ。

final Fields and Constants

  • finalなフィールド変数は、値を変更しても、その値を参照している既存バイナリは再コンパイルしない限り新しい値が適用されない。
  • 定数式で初期化しなくとも、同じ動作となる。
  • この動作は条件付コンパイルをサポートした結果の副作用である。
  • 定数は絶対に変更されない値でのみ宣言するべき。
  • 単に読み込み専用としたい場合はprivate staticな変数のgetterのみ宣言する方が良い。
  • 定数値を持つstatic finalなフィールドはデフォルト初期値を持つように宣言してはならない。必ず定数式で初期化する。
    • × static final int a;
    • static final int a = 0;

ブランクfinalはインライン展開されない模様。
言語仕様では明確な記述は発見できなかった。

[java]
class Constant1
{
public static final String A;

static
{
A = “test”;
}

}
class Constant2
{
public static final String A = “test”;
}

public class Main
{
public static void main(String[] args)
{
System.out.println(Constant1.A);
//decompile=>System.out.println(Constant1.A)

System.out.println(Constant2.A);
//decompile=>System.out.println(“test”)
}
}
[/java]

7月 132012
 

バグ?

Checkstyle4.3.2で確認。

  • Checkstyleでは8文字カウントがデフォルト値
  • Eclipse上での設定画面では4文字がデフォルト値として認識している(※バグぽ)
  • Eclipse上での設定画面で4文字指定を行うと、デフォルト値と認識されて設定ファイルからカウント数設定を削除する
  • 設定ファイルはXMLだが、タブ文字カウント数の設定が存在しないとデフォルト値の8文字としてカウントする
解決策1

Checkstyle設定画面にてOther>TreeWalker>tabWidthを4にする。
SizeViolations>MaximumLineLength>tabWidthはバグにより4文字指定不可

解決策2

設定ファイルをテキストエディタで開き、TreeWalkerモジュールか、LineLengthモジュールに以下のプロパティを設定する。

[xml][/xml]

TreeWalkerモジュールに設定した場合は解決策1と同様の設定になる。