[[compat_mode]]
==  Compatibility Mode

[WARNING]
====
Compatibility mode is deprecated and will be removed from {brandname}. To achieve interoperability between remote endpoints, you should use protocol interoperability capabilities. See link:#endpoint_interop[Protocol Interoperability].
====

Compatibility mode configures {brandname} caches so that you can access {brandname} in multiple ways. Achieving such compatibility requires extra work from {brandname} in order to make sure that contents are converted back and forth between the different formats of each endpoint and this is the reason why compatibility mode is disabled by default.

=== Enable Compatibility Mode
For compatibility mode to work as expected, all endpoints need to be configured with the same cache manager, and need to talk to the same cache. If you're using the brand new link:http://www.jboss.org/infinispan/downloads[{brandname} Server distribution] , this is all done for you. If you're in the mood to experiment with this in a standalone unit test, link:https://github.com/infinispan/infinispan/blob/master/integrationtests/compatibility-mode-it/src/test/java/org/infinispan/it/compatibility/CompatibilityCacheFactory.java[this class] shows you how you can start multiple endpoints from a single class.

So, to get started using {brandname}'s compatibility mode, it needs to be enabled, either via XML:

.infinispan.xml
[source,xml]
----

<local-cache>
   <compatibility/>
</local-cache>

----

Or programmatically:

[source,java]
----

ConfigurationBuilder builder = ...
builder.compatibility().enable();

----

The key thing to remember about {brandname}'s compatibility mode is that where possible, it tries to store data unmarshalling or deserializing it. It does so because the most common use case is for it to store Java objects and having Java objects stored in deserialized form means that they're very easy to use from an embedded cache. With this in mind, it makes some assumptions. For example, if something is stored via Hot Rod, it's most likely coming from the reference Hot Rod client, which is written in Java, and which uses a marshaller that keeps binary payloads very compact. So, when the Hot Rod operation reaches the compatibility layer, it will try to unmarshall it, by default using the same default marshaller used by the Java Hot Rod client, hence providing good out-of-the-box support for the majority of cases.

==== Optional: Configuring Compatibility Marshaller
It could happen though the client might be using a Hot Rod client written for another language other than Java, say link:https://github.com/infinispan/ruby-client[Ruby] or link:https://github.com/infinispan/python-client[Python] . In this case, some kind of custom marshaller needs to be configured that either translates that serialized payload into a Java object to be stored in the cache, or keeps it in serialized form. Both options are valid, but of course it will have an impact on what kind of objects are retrieved from {brandname} if using the embedded cache. The marshaller is expected to implement link:{javadocroot}/org/infinispan/commons/marshall/Marshaller.html[this interface]. Configuring the compatibility marshaller is optional and can be done via XML:

.infinispan.xml
[source,xml]
----

<local-cache>
   <compatibility marshaller="com.acme.CustomMarshaller"/>
</local-cache>

----

Or programmatically:

[source,java]
----

ConfigurationBuilder builder = ...
builder.compatibility().enable().marshaller(new com.acme.CustomMarshaller());

----

One concrete example of this marshaller logic can be found in the link:https://github.com/infinispan/infinispan/blob/master/integrationtests/compatibility-mode-it/src/test/java/org/infinispan/it/compatibility/EmbeddedRestMemcachedHotRodTest.java#L161[SpyMemcachedCompatibleMarshaller] . link:https://code.google.com/p/spymemcached/[Spy Memcached] uses their own transcoders in order to marshall objects, so the compatibility marshaller created is in charge of marshalling/unmarshalling data stored via Spy Memcached client. If you want to retrieve data stored via Spy Memcached via say Hot Rod, you can configure the Java Hot Rod client to use this same marshaller, and this is precisely what the test where the Spy Memcached marshaller is located is demonstrating.

=== Code examples
The best code examples available showing compatibility in action can be found in the link:https://github.com/infinispan/infinispan/tree/master/integrationtests/compatibility-mode-it/src/test/java/org/infinispan/it/compatibility[{brandname} Compatibility Mode testsuite], but more will be developed in the near future.
