Created
January 17, 2010 10:16
-
-
Save ashigeru/279325 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Hibernate { | |
public static void main(String[] args) throws Exception { | |
// 次の状態を起動して、終わったらその次の状態を保存 | |
save(restore().call()); | |
} | |
@MakeCallable | |
static Callable<?> start() { | |
System.out.println("最初"); | |
return HibernateDefer.next(); | |
} | |
@MakeCallable | |
static Callable<?> next() { | |
System.out.println("次"); | |
return HibernateDefer.loop(); | |
} | |
@MakeCallable | |
static Callable<?> loop() { | |
System.out.println("繰り返し"); | |
return HibernateDefer.next(); | |
} | |
private static File file = new File("hibernate.bin"); | |
private static Callable<?> restore() { | |
try { | |
// ファイルから次の状態を復元 | |
FileInputStream in = new FileInputStream(file); | |
try { | |
ObjectInputStream ois = new ObjectInputStream(in); | |
return (Callable<?>) ois.readObject(); | |
} | |
finally { | |
in.close(); | |
} | |
} | |
catch (IOException e) { | |
// 読み出すのに失敗したらstart()から | |
return HibernateDefer.start(); | |
} | |
catch (Exception e) { | |
throw new AssertionError(e); | |
} | |
} | |
private static void save(Object object) throws IOException { | |
FileOutputStream out = new FileOutputStream(file); | |
try { | |
// 次の状態を書き出す | |
ObjectOutputStream oos = new ObjectOutputStream(out); | |
oos.writeObject(object); | |
oos.close(); | |
} | |
finally { | |
out.close(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment