Main Contents
2009年5月 3日
2008年5月 5日
GW 中にやったこと
GW 中にやったことをちょっとまとめてみる...
インフラまわりは, ほとんど深夜やっていたので, 寝るのは午前中って感じでした...
でも, かなりすっきり.
確定申告
毎年のことなのですが, うちの会社の「確定深刻」は GW 勝負なのです(汗)
今年は, e-Tax を使ってみましたが, イマイチ便利になってない...
税務署へ持って行く手間はなくなりましたが, 事業税などの申告は別にやらなきゃいけないし, 電子証明書の申請をしに法務局へ行かなきゃいけない.
数字の計算くらい, 明細書から自動計算してくれれば楽なのに(苦笑)
FreeBSD 4.x-RELEASE から 6.3-RELEASE へのアップグレード
FreeBSD 4.11-RELEASE が, まだ4台稼動していたので, すべて 6.3-RELEASE にアップグレード.
Celeron 700MHz という骨董品ですが, これでまた, 暫くは心おきなく使えますw
手順は, 下記とほとんど同じ
FreeBSD4 から FreeBSD6 へのアップグレード
jail でまとめる
上記の FreeBSD4.11-RELEASE で稼動していたうちの3台を, jail(8) を使って1台に統合しました.
減らしたやつは, 予備機として頑張ってもらいます.
sysutils/ezjail を使って構築も楽ちん.
ipfilter から pf へ乗り替え
ipfilter は, 今後メンテされなくなるようなので, 6.3-RELEASE へアップグレードしたついでに, pf へ乗り替え.
構文もすっきりして, メンテもしやすくなりました.
特に, ルータとして使っているやつは, 細かい設定ができてステキ.
set block-policy drop とか良い感じです.
下記を参考にしました
FreeBSDでPacketFilter(pf)を使う
過去の遺産の整理...
4.11-RELEASE が現在までも稼動していたのもそうですが, 過去に書いたバックアップスクリプトとかを, メンテしやすいようにいろいろ更新. サーバーで USBキーボードを使えるようにしたりだとか...
あ, DHCP サーバーも jail(8) で動くようにして, WIDE-DHCP を net/isc-dhcpd-server にしました.
Firemacs のアイコン

山本さん, 大変永らくお待たせ致しました...(汗)
また, 拙作のアイコンをご採用頂き, ありがとうございました!
心残り...
EC-CUBE をほとんど触れなかったのがざんねん...
もうちょっと精進します...
- by みそ
- at 20:09
- in Applications
2008年4月27日
NTEmacs にしてみた
今まで, Windows 環境では Meadow を使っていましたが, NTEmacs もちょっと気になって NTEmacsJp project の NTEmacs を入れてみました.
そしたら, アイコンが Emacs23 と同タイプになっているではありませんか!!
感謝感激!! 廣松さん, ありがとうございます!
使い心地は, 良い感じ.
気のせいかもしれませんが, Meadow に比べると, ちょっと速くなったような感じがします.
でも, Meadow みたいに NetInstall で簡単に設定することができないので, 玄人向けですね.
しかし, Windows 環境でも, Emacs23 のアイコンが使えてシアワセです.
- by みそ
- at 02:29
- in Emacs
2008年4月21日
BeanUtils の使い方
かなり前に書いた記事を, ちゃんとまとめてみました.
BeanUtils の使い方サンプルです.
JUnit4 のテストケースとして書いてみました.
/*
* $Id$
*/
package net.nanasess.examples;
import static org.junit.Assert.*;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.PropertyUtils;
import org.junit.Before;
import org.junit.Test;
/**
* BeanUtils の使い方.
*
* 基本的に, データ型を String に変換して返します.
* 変換したくない場合は, {@link PropertyUtils} を使います.
*
* @author Kentaro Ohkouchi
* @version $Revision$ $Date$
*/
public class BeanUtilsTest {
private FooBar fooBar;
@Before
public void before() {
fooBar = new FooBar();
}
/**
* {@link BeanUtils#cloneBean(java.lang.Object)} の使い方.
*
* Cloneable を implements してなくても Bean の複製ができます.
*/
@Test
public final void testCloneBean() throws Exception {
Bar bar = new Bar("bar");
String excepted = "bar";
// bar を複製する
Bar actual = (Bar) BeanUtils.cloneBean(bar);
assertEquals(excepted, actual.getExample());
}
/**
* {@link BeanUtils#copyProperties(java.lang.Object, java.lang.Object)} の使い方
*
* 同じプロパティ名のデータを orig から dest へコピーします.
* この場合, example というプロパティが双方に存在するので, example のデータがコピーされます.
*/
@Test
public final void testCopyProperties() throws Exception {
Bar orig = new Bar();
ExampleClass dest = new ExampleClass();
// 同じプロパティ名のデータを orig から dest へコピーする.
BeanUtils.copyProperties(dest, orig);
// orig が Map の場合は, プロパティ名と Map の key が一致した場合コピーされる.
Map map = new HashMap();
map.put("foo", "foo");
BeanUtils.copyProperties(dest, map);
// example の内容がコピーされる
assertEquals(orig.getExample(), dest.getExample());
// Map の内容もコピーされる
assertEquals(map.get("foo"), dest.getFoo());
// baz は null のまま
assertNull(dest.getBaz());
}
/**
* {@link BeanUtils#copyProperty(java.lang.Object, java.lang.String, java.lang.Object)} の使い方.
*
* 指定したプロパティのデータをコピーします.
* ネストしたプロパティもコピーできます.
*/
@Test
public final void testCopyProperty() throws Exception {
Bar bar = new Bar();
ExampleClass bean = new ExampleClass();
// 指定したプロパティのデータを bean にコピーします.
BeanUtils.copyProperty(bean, "foo", "foo");
// ネストした Bean もコピーできます.
BeanUtils.copyProperty(bean, "bar", bar);
assertEquals("foo", bean.getFoo());
assertEquals("example", bean.getBar().getExample());
}
/**
* {@link BeanUtils#describe(java.lang.Object)} の使い方.
*
* bean のプロパティ名を key, プロパティのデータを value とした Map を返します.
* プロパティのデータ型に関わらず, value は String になります...
*/
@Test
public final void testDescribe() throws Exception {
// value に格納されるデータを String にキャストして Map で返します.
Map map = BeanUtils.describe(fooBar);
assertEquals("foo", map.get("foo"));
}
/**
* {@link BeanUtils#getArrayProperty(java.lang.Object, java.lang.String)} の使い方.
*
* プロパティ名を指定して, プロパティの値を String の配列で返します.
* プロパティのデータ型が配列の場合は, String の配列に変換して返します.
* コレクションの場合も, String の配列に変換して返します.
* それ以外のデータ型の場合は, {@link Object#toString()} の値を String の配列に格納して返します.
*/
@Test
public final void testGetArrayProperty() throws Exception {
// プロパティ名を指定して, String の配列を返します.
String[] strings = BeanUtils.getArrayProperty(fooBar, "strings");
assertArrayEquals(fooBar.getStrings(), strings);
// プロパティが配列では無い場合も String の配列が返ってきます.
String[] foo = BeanUtils.getArrayProperty(fooBar, "foo");
assertArrayEquals(new String[]{"foo"}, foo);
}
/**
* {@link BeanUtils#getIndexedProperty(java.lang.Object, java.lang.String)} の使い方.
*
* プロパティ名[インデックス番号] のように, インデックスを保持するプロパティから, インデックス番号を指定して
* 値を String で返します.
* インデックスを保持しないプロパティは, {@link IllegalArgumentException} になります.
*/
@Test(expected=IllegalArgumentException.class)
public final void testGetIndexedPropertyObjectString() throws Exception {
// プロパティ名とインデックス番号を指定して String の値を返します.
String actual = BeanUtils.getIndexedProperty(fooBar, "strings[2]");
assertEquals("ghi", actual);
// インデックスを保持しないプロパティは IllegalArgumentException になります.
String foo = BeanUtils.getIndexedProperty(fooBar, "foo[0]");
}
/**
* {@link BeanUtils#getIndexedProperty(java.lang.Object, java.lang.String, int)} の使い方.
*
* {@link BeanUtils#getIndexedProperty(java.lang.Object, java.lang.String)} に
* 似ていますが, インデックス番号を int で指定するところが異なります.
*/
@Test
public final void testGetIndexedPropertyObjectStringInt() throws Exception {
// プロパティ名とインデックス番号を指定して, String の値を取得します.
String actual = BeanUtils.getIndexedProperty(fooBar, "strings", 2);
assertEquals("ghi", actual);
}
/**
* {@link BeanUtils#getMappedProperty(java.lang.Object, java.lang.String)} の使い方.
*
* プロパティが Map の場合, プロパティ名(key) のように指定して, 値を String で返します.
* プロパティが Map 以外の場合は, null を返します.
*/
@Test
public final void testGetMappedPropertyObjectString() throws Exception {
// プロパティ名と key を指定して, String の値を返します.
String actual = BeanUtils.getMappedProperty(fooBar, "map(abc)");
assertEquals("abc of value", actual);
// プロパティが Map 以外の場合は, null を返します.
assertNull(BeanUtils.getMappedProperty(fooBar, "foo(key)"));
}
/**
* {@link BeanUtils#getMappedProperty(java.lang.Object, java.lang.String, java.lang.String)} の使い方.
*
* {@link BeanUtils#getMappedProperty(java.lang.Object, java.lang.String)} に
* 似ていますが, key を第3引数で指定するところが異なります.
*/
@Test
public final void testGetMappedPropertyObjectStringString() throws Exception {
// プロパティ名と key を指定して, String の値を返します.
String actual = BeanUtils.getMappedProperty(fooBar, "map", "abc");
assertEquals("abc of value", actual);
}
/**
* {@link BeanUtils#getNestedProperty(java.lang.Object, java.lang.String)} の使い方.
*
* ネストした Bean のプロパティをドットシンタックスで取得できます.
* 値は String で返します.
*/
@Test
public final void testGetNestedProperty() throws Exception {
// ネストしたプロパティを取得します.
String actual = BeanUtils.getNestedProperty(fooBar, "bar.example");
assertEquals("example", actual);
}
/**
* {@link BeanUtils#getProperty(java.lang.Object, java.lang.String)} の使い方.
*
* 便利屋さんです.
* プロパティのデータ型に合わせた方法で, プロパティ名やインデックスを指定することで, プロパティの値を
* String で取得できます.
*/
@Test
public final void testGetProperty() throws Exception {
// プロパティ名を指定して String の値を返します.
String foo = BeanUtils.getProperty(fooBar, "foo");
assertEquals("foo", foo);
// プロパティ名とインデックス番号を指定して String の値を返します.
String strings = BeanUtils.getProperty(fooBar, "strings[2]");
assertEquals("ghi", strings);
// プロパティ名と key を指定して, String の値を返します.
String map = BeanUtils.getProperty(fooBar, "map(abc)");
assertEquals("abc of value", map);
// ネストしたプロパティを取得します.
String actual = BeanUtils.getProperty(fooBar, "bar.example");
assertEquals("example", actual);
}
/**
* {@link BeanUtils#getSimpleProperty(java.lang.Object, java.lang.String)} の使い方.
*
* プロパティ名を指定して, String の値を返します.
* {@link BeanUtils#getProperty(java.lang.Object, java.lang.String)} とは挙動が
* 異なるため, 単純な Bean の値を取得するのに適しています.
*/
@Test(expected=IllegalArgumentException.class)
public final void testGetSimpleProperty() throws Exception {
// プロパティ名を指定して String の値を返します.
String foo = BeanUtils.getSimpleProperty(fooBar, "foo");
assertEquals("foo", foo);
// プロパティが配列の場合は先頭の値を返します.
String strings = BeanUtils.getSimpleProperty(fooBar, "strings");
assertEquals("abc", strings);
// プロパティが Map の場合はMap#toString() の値を返します.
String map = BeanUtils.getSimpleProperty(fooBar, "map");
assertEquals("{abc=abc of value, ghi=ghi of value, def=def of value}", map);
// ネストしたプロパティは取得できません...
try {
BeanUtils.getSimpleProperty(fooBar, "bar.example");
} catch (IllegalArgumentException e) {
throw e;
}
}
/**
* {@link BeanUtils#populate(java.lang.Object, java.util.Map)} の使い方.
*
* Map に格納した値を key に対応する Bean のプロパティに設定します.
* 値は, String にキャストして設定します.
*/
@Test
public final void testPopulate() throws Exception {
Map map = new HashMap();
map.put("foo", "foo of value");
map.put("bar.example", new Integer(1000));
// Map の key に対応するプロパティに値を設定します.
BeanUtils.populate(fooBar, map);
assertEquals("foo of value", fooBar.getFoo());
// Integer などの値も String にキャストされます.
assertEquals("1000", fooBar.getBar().getExample());
}
/**
* {@link BeanUtils#setProperty(java.lang.Object, java.lang.String, java.lang.Object)} の使い方.
*
* {@link BeanUtils#getProperty(java.lang.Object, java.lang.String)} と同様の方法で,
* プロパティ名を指定することで, 任意のオブジェクトを String にキャストして Bean に設定します.
*/
@Test
public final void testSetProperty() throws Exception {
// プロパティ名を指定して String の値を設定します.
BeanUtils.setProperty(fooBar, "foo", "foo of value");
assertEquals("foo of value", fooBar.getFoo());
// プロパティ名とインデックス番号を指定して String の値を設定します.
BeanUtils.setProperty(fooBar, "strings[2]", "strings of two");
String[] strings = fooBar.getStrings();
assertEquals("strings of two", strings[2]);
// プロパティ名と key を指定して, String の値を設定します.
BeanUtils.setProperty(fooBar, "map(abc)", new Integer(1000));
assertEquals("1000", fooBar.getMap().get("abc"));
// ネストしたプロパティを設定します.
BeanUtils.setProperty(fooBar, "bar.example", "bar of example");
assertEquals("bar of example", fooBar.getBar().getExample());
}
}
Bean は下記のものを使っています.
/*
* $Id$
*/
package net.nanasess.examples;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* FooBar クラス.
*
* 内部で Bar クラスをネストしている.
*
* @author Kentaro Ohkouchi
* @version $Revision$ $Date$
*/
public class FooBar {
private String foo;
private Bar bar;
private String[] strings;
private List bars;
private Map map;
public FooBar() {
this.foo = "foo";
bar = new Bar();
strings = new String[]{"abc", "def", "ghi"};
bars = new ArrayList();
map = new HashMap();
for (String string : strings) {
bars.add(new Bar(string));
map.put(string, string + " of value");
}
}
public String getFoo() {
return foo;
}
public void setFoo(String foo) {
this.foo = foo;
}
public Bar getBar() {
return bar;
}
public void setBar(Bar bar) {
this.bar = bar;
}
public String[] getStrings() {
return strings;
}
public void setStrings(String[] strings) {
this.strings = strings;
}
public List getBars() {
return bars;
}
public void setBars(List bars) {
this.bars = bars;
}
public Map getMap() {
return map;
}
public void setMap(Map map) {
this.map = map;
}
}
/*
* $Id$
*/
package net.nanasess.examples;
import java.sql.Timestamp;
/**
* Bar クラス.
*
* @author Kentaro Ohkouchi
* @version $Revision$ $Date$
*/
public class Bar {
private String example;
private Timestamp created;
public Bar() {
this.example = "example";
this.created = new Timestamp(System.currentTimeMillis());
}
public Bar(String example) {
this.example = example;
this.created = new Timestamp(System.currentTimeMillis());
}
public String getExample() {
return example;
}
public void setExample(String example) {
this.example = example;
}
public Timestamp getCreated() {
return created;
}
public void setCreated(Timestamp created) {
this.created = created;
}
}
/*
* $Id$
*/
package net.nanasess.examples;
import java.sql.Timestamp;
/**
* ExampleClass クラス.
*
* @author Kentaro Ohkouchi
* @version $Revision$ $Date$
*/
public class ExampleClass {
private String foo;
private String baz;
private String example;
private Bar bar;
private Timestamp created;
public String getFoo() {
return foo;
}
public void setFoo(String foo) {
this.foo = foo;
}
public String getBaz() {
return baz;
}
public void setBaz(String baz) {
this.baz = baz;
}
public String getExample() {
return example;
}
public void setExample(String example) {
this.example = example;
}
public Bar getBar() {
return bar;
}
public void setBar(Bar bar) {
this.bar = bar;
}
public Timestamp getCreated() {
return created;
}
public void setCreated(Timestamp created) {
this.created = created;
}
}
以前の記事にも書いたのですが, BeanUtils は, 基本的に値を String にキャストします.
PropertyUtils は, 型変換せずに扱います.
それ以外の振舞いは, 基本的に同じです.
これらの API を使いこなすと非常に強力ですが, 最近はフレームワークがサポートしている場合が多いようです.
(Seasar の S2BeanUtils など)
今回ひさびさに,
- Permalink
- Trackbacks (2)
-
- by みそ
- at 01:47
- in Java
2008年4月20日
JUnit4 ことはじめ
ずっと食わず嫌いだった JUnit4 を使ってみたので, コードを晒しておきます...
/*
* $Id$
*/
package net.nanasess.examples;
import java.util.ArrayList;
import java.util.List;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* HelloWorld のテスト.
*
* @author Kentaro Ohkouchi
* @version $Revision$ $Date$
*/
public class HelloWorldTest {
private static String expected;
private String actual;
private static int counter;
/**
* すべてのテスト前に実行するメソッド.
*
* static にして {@link @beforeClass} アノテーションをつける.
*/
@BeforeClass
public static void beforeClass() {
System.out.println("HelloWorld テストを始めます.");
counter = 0;
System.out.println("カウンターを初期化しました.");
}
/**
* すべてのテストを終了した後に実行するメソッド.
*
* static にして {@link @AfterClass} アノテーションをつける.
*/
@AfterClass
public static void afterClass() {
System.out.println(counter + " 個のテストを実行しました.");
System.out.println("HelloWorld テストを終了します.");
}
/**
* 各テストをする前に実行するメソッド.
*
* {@link @Before} アノテーションをつける.
*/
@Before
public void before(){
expected = "HelloWorld";
System.out.println("expected を初期化しました.");
}
/**
* 各テストの後に実行するメソッド.
*
* {@link @After} アノテーションをつける.
*/
@After
public void after() {
counter++;
System.out.println(String.valueOf(counter) + " 番目のテストを実行しました.");
}
/**
* HelloWorld のテスト.
*/
@Test
public void helloWorld() {
actual = "HelloWorld";
assertEquals(expected, actual);
}
/**
* ちゃんと ClassNotFoundException になるかどうかのテスト.
*
* @throws Exception エラーが発生した場合.
*/
@Test(expected = ClassNotFoundException.class)
public void classForNameFailure() throws Exception {
Class.forName("org.postgresql.Driver");
}
/**
* スタブなので, スキップするテスト.
*
* {@link @Ignore} アノテーションをつけると, そのメソッドはテストしない.
*/
@Ignore("スタブなのでテストしません...")
@Test
public void testStub() {
assertEquals("test", "stub");
}
/**
* 配列を比較するテスト.
*
* {@link org.junit.Assert#assertArrayEquals(String[], String[])} を使ってます.
* 配列や, List のテストも楽になったものです(しみじみ)
*/
@Test
public void arrays() {
String[] expecteds = { "1", "2", "3" };
List actuals = new ArrayList();
actuals.add("1");
actuals.add("2");
actuals.add("3");
assertArrayEquals(expecteds, actuals.toArray(new String[actuals.size()]));
}
}
個人的には, 配列や例外のテストが解りやすく楽になったのが良い感じ.
JUnit4 の関連ライブラリも充実してきたので, そろそろ乗り替え時かな...
ついでに, Eclipse 3.4M6a を Celeron 600MHz, メモリ 384MB という非力なノートPCで使ってみましたが, 思ったよりサクサクで良い感じでした☆
- Permalink
- Trackbacks (1)
-
- by みそ
- at 16:05
- in Java
2008年4月16日
sitemap.xml
MT4 で サイトマップ(sitemap.xml)を作成 を参考に, sitemap.xml も作ってみました.
FastCGI といい, こうやって細かいチューニングができるのは, 自前サーバーの強みですね...
- by みそ
- at 22:55
- in Movable Type
MovableType を FastCGI で動作させる
最近, スパムコメントやスパムトラックバックで, サーバーの負荷が酷な状態になっていたため, 負荷低減のために MovableType を FastCGI で動作するようにしてみました.
参考 http://wiki.movabletype.org/Hosting_MT_under_FastCGI_(Japanese)
- まず, 必要なライブラリをインストール. FreeBSD なので ports から...
# portinstall www/p5-FastCGI # portinstall www/mod_fastcgiportupgrade を使わない場合は, /usr/ports/www/p5-FastCGI, /usr/ports/www/mod_fastcgi で make install で OK - httpd.conf に以下を追加
LoadModule fastcgi_module libexec/apache2/mod_fastcgi.so <IfModule fastcgi_module> FastCgiIpcDir /var/tmp/fcgi_ipc/ AddHandler fastcgi-script fcgi FastCGIConfig -autoUpdate -idle-timeout 120 -killInterval 3600 -maxClassProcesses 6 -maxProcesses 15 </IfModule> - mod_fastcgi を有効にするため, apache を再起動
# apachectl restart
- MovableType の mt*.cgi を mt*.fcgi にリネーム. とりあえず mt*.cgi も動くようにコピーしました.
$ cp mt.cgi mt.fcgi $ cp mt-tb.cgi mt-tb.cgi $ cp mt-comments.cgi mt-comments.fcgi $ cp mt-search.cgi mt-search.fcgi $ cp mt-view.cgi mt-view.fcgi
- mt-config.cgi の編集. とりあえず必要な箇所のみ *.fcgi にしました.
AdminScript mt.fcgi CommentScript mt-comments.fcgi TrackbackScript mt-tb.fcgi SearchScript mt-search.fcgi # XMLRPCScript mt-xmlrpc.pl ViewScript mt-view.fcgi # AtomScript mt-atom.pl # UpgradeScript mt-upgrade.pl
あとは, mt.fcgi にアクセスして, FastCGI で動作することを確認し, サイトをすべて再構築してやれば OK です.
これで負荷が減ってくれれば良いのですが...
MovableType を FastCGI で動作させるの続きを読む
- by みそ
- at 17:27
- in FreeBSD
This weblog is licensed under a Creative Commons License.