TerracottaでwebアプリのTIMを入れてものセッションクラスタリングをしないようにする

WEBアプリケーションでTerracottaを使うときはtim-tomcatとかのインテグレーションモジュールを入れて使うのが推奨されています。
例えば、WEBアプリでキャッシュ機構にEHCacheを使う場合のtc-config.xmlはこんな感じ。

<?xml version="1.0" encoding="UTF-8"?>
<tc:tc-config xmlns:tc="http://www.terracotta.org/config"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.terracotta.org/schema/terracotta-5.xsd">

	<servers>

		<!--
			For more information on working with the Terracotta configuration
			file, including how to add more servers, see
			http://www.terracotta.org/web/display/docs/About+Terracotta+Configuration+Files.

			Edit the following server element so that its host attribute contains
			the value matching the hostname for the Terracotta server.
		-->

		<server host="localhost">
			<dso-port>9510</dso-port>
		</server>

		<update-check>
			<enabled>false</enabled>
		</update-check>

	</servers>

	<!--
		Check that the TIM shown in the <module> element's name attribute
		matches the Tomcat version you are using. The TIM listed here,
		"tim-tomcat-5.5" is for Tomcat 5.5. For example, if you are using
		Tomcat 6.0, edit the name to "tim-tomcat-6.0".
	-->

	<clients>
		<modules>
			<module name="tim-ehcache-1.7" version="1.4.1" />
			<module name="tim-tomcat-6.0" version="2.0.2" />
		</modules>
	</clients>

	<!--
		Using <web-application> elements, enter the context root of the web
		application being clustered. If you are clustering more than one web
		application, use one <web-application> element per application. Two
		example <web-application> elements are shown below. Edit or remove
		these elements as needed. To set the value of the <web-application>
		element to the default web-application context, use the special value
		"ROOT" (without quotation marks).
	-->

	<application>
		<dso>
			<web-applications>
				<web-application>MyWebApp</web-application>
			</web-applications>
		</dso>
	</application>
</tc:tc-config>

みたいな。

実際には、Terracotta3.1.1+EHCache1.7.0からは統合されているので、tc-config.xmlとかtimモジュールとかはクライアントに用意する必要もないし、サーバー側のtc-config.xmlにもtim-tomcatの設定を書く必要はないけど。

セッションクラスタリングなしでTIMを使う

ですがこのconfigでの曲者がweb-applicationsセクションで、これを書くとセッションクラスタリングもしようとしてしまって、ちょっと困る場面もあります。

http://www.terracotta.org/web/display/docs/Configuration+Guide+and+Reference#ConfigurationGuideandReference-ApplicationConfigurationSection

なので、tomcatへのインテグレーションモジュールを使いながら、セッションクラスタリングをしない場合にはこういう設定を書く必要があります。

<?xml version="1.0" encoding="UTF-8"?>
<tc:tc-config xmlns:tc="http://www.terracotta.org/config"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.terracotta.org/schema/terracotta-5.xsd">

	<servers>
		<!--
			For more information on working with the Terracotta configuration
			file, including how to add more servers, see
			http://www.terracotta.org/web/display/docs/About+Terracotta+Configuration+Files.

			Edit the following server element so that its host attribute contains
			the value matching the hostname for the Terracotta server.
		-->
		<server host="localhost">
			<dso-port>9510</dso-port>
		</server>

		<update-check>
			<enabled>false</enabled>
		</update-check>

	</servers>

	<!--
		Check that the TIM shown in the <module> element's name attribute
		matches the Tomcat version you are using. The TIM listed here,
		"tim-tomcat-5.5" is for Tomcat 5.5. For example, if you are using
		Tomcat 6.0, edit the name to "tim-tomcat-6.0".
	-->

	<clients>
		<modules>
			<module name="tim-ehcache-1.7" version="1.4.1" />
			<module name="tim-tomcat-6.0" version="2.0.2" />
		</modules>
	</clients>

	<!--
		Using <web-application> elements, enter the context root of the web
		application being clustered. If you are clustering more than one web
		application, use one <web-application> element per application. Two
		example <web-application> elements are shown below. Edit or remove
		these elements as needed. To set the value of the <web-application>
		element to the default web-application context, use the special value
		"ROOT" (without quotation marks).
	-->

	<application>
		<dso>
			<app-groups>
				<app-group name="MyApps">
					<web-application>MyWebApp</web-application>
				</app-group>
			</app-groups>
		</dso>
	</application>
</tc:tc-config>

ポイントはapp-groupでアプリ名を指定することみたい。ただweb-applicationsセクションを削っただけだと、

Caused by: com.tc.exception.TCClassNotFoundException: java.lang.ClassNotFoundException: Detected different clustered applications trying to share the same Terracotta root. See the "/app-groups" section in the Terracotta Configuration Guide and Reference (http://www.terracotta.org/kit/reflector?kitID=3.1&pageID=ConfigGuideAndRef) for more information on how to configure application groups.
	at com.tc.object.ClientObjectManagerImpl.lookupOrCreateRoot(ClientObjectManagerImpl.java:654)
	at com.tc.object.bytecode.ManagerImpl.lookupOrCreateRoot(ManagerImpl.java:334)
	at com.tc.object.bytecode.ManagerImpl.lookupOrCreateRoot(ManagerImpl.java:313)
	at com.tc.object.bytecode.ManagerUtil.lookupOrCreateRoot(ManagerUtil.java:128)
	at org.terracotta.modules.ehcache.store.TerracottaStoreFactory.getStoreRoot(TerracottaStoreFactory.java:88)
	at org.terracotta.modules.ehcache.store.TerracottaStoreFactory.create(TerracottaStoreFactory.java:33)
	at net.sf.ehcache.CacheManager.createTerracottaStore(CacheManager.java:325)
	at net.sf.ehcache.Cache.initialise(Cache.java:694)
	at net.sf.ehcache.CacheManager.addCacheNoCheck(CacheManager.java:784)
	at net.sf.ehcache.CacheManager.addConfiguredCaches(CacheManager.java:472)
	at net.sf.ehcache.CacheManager.init(CacheManager.java:302)
	at net.sf.ehcache.CacheManager.(CacheManager.java:248)

とかの例外がでて、違うアプリケーションから分散共有メモリに接続しようとしちゃダメ!って怒られた。

ちなみに
    <web-applications>
      <web-application>FooWebApp</web-application>
      <web-application session-locking="false">FooWebApp</web-application>
    </web-applications>

でセッションクラスタリングしないようになるかなと思ったけどダメだった。