1/28/2011

Java Daemon 撰寫與佈署

這篇不是真正教如何設計Java Daemon,考量如何利用別人寫好的Java Daemon能夠比較容易整合於不同環境中。 如通常不會自行開發工作排程系統,利用已成熟Quarts為基礎往上堆應用程式,雖然是已成熟Java Daemon要如何整合於不同的作業系統(Linux, Windows, Mac) ?

這個問題說難不難說簡單不簡單,解決方案也五花八門。傳統方式就是撰寫 public static void main(String[]) 統一由這一支Java程式啟動服務,然後撰寫一堆shell呼叫, 雖然問題也是可以解決但是往後系統維護管理不易也沒有統一。

Apache Commons Daemon 專案滿不錯解決方案之一

...Most multi-user operating systems already have a way in which server applications are started and stopped. Under Unix based operating systems non interactive server applications are called daemons and are controlled by the operating system with a set of specified signals. Under Windows such programs are called services and are controlled by appropriate calls to specific functions defined in the application binary, but although the ways of dealing with the problem are different, in both cases the operating system can notify a server application of its imminent shutdown, and the application has the ability to perform certain tasks before its process of execution is destroyed.

1/17/2011

How to test job in Quartz

之前工作排程都是使用Java Quartz來設計,但確沒有好好想過要如何測試 (有時候承認不夠好或許就是進步泉源),真的很不應該!

工作排程環境要模擬也確實滿複雜,但可利用Mock觀念 讓我們追縱瞭解物件內部流程,確保物件活動如預期中運作。

Java Runtime exec

使用Java執行外部指令( ls, pwd....) OSX環境執行的很好,但在windows環境確整個掛住跑不動(Java真的有跨平台嗎?),搞了一下午才弄清楚。

原本程式極為單純容易,但是會在windows 環境掛住!

最後才發現原來祕密寫在Process Java Doc說明裡:

1/13/2011

好玩VimGolf

VimGolf讓你挑戰用Vim解決各式各樣的文字編輯問題,會有分數統計排行...

  1. gem install vimgolf
  2. vimgolf setup
  3. vimgolf put [challenge ID]

vimgolf put 4d1ed78425ba287b2a000227

使用Vim解決CSV to JSON問題,vimgolf會將你所有編輯動作記錄下來算出一個分數上傳到vimgolf.com,有很多題目都很難看來Vim還不是多熟Orz!

1/12/2011

安裝rabbitmq server

在OSX環境安裝RabbitMQ Server

  • brew update
  • brew install rabbitmq
  • startup rabbitmq server

  • sudo rabbitmq-server
  • shudown rabbitmq server

  • sudo rabbitmqctl stop
  • show queues

  • sudo rabbitmqctl list_queues