Friday, August 24, 2012

How to use ADF MDS without enabling ADF security


MDS needs some way to uniquely identify each logged in user. Sometimes we might have applications that don't use ADF Security. We have to write a custom class that helps MDS to distinguish users. You start with a class that extends oracle.mds.cust.CustomizationClass. You need to modify the code in red to get a unique value that identifies the logged in user.

package a.b.c;
import java.util.Map;import javax.faces.context.FacesContext;import oracle.mds.core.MetadataObject;
import oracle.mds.core.RestrictedSession;
import oracle.mds.cust.CacheHint;
import oracle.mds.cust.CustomizationClass;

public class MyUserCC extends CustomizationClass {
    private static final String DEFAULT_LAYER_NAME = "user";
    private String mLayerName;

    public MyUserCC () {
        mLayerName = "user";
    }

    public CacheHint getCacheHint() {
        return CacheHint.USER;
    }

    public String getName() {
        return mLayerName;
    }

// Change code in this method to get the current logged in user   
public String[] getValue(RestrictedSession sess, MetadataObject mo) {
  String user = null;

// Change the code below to suits your application    FacesContext ctx = FacesContext.getCurrentInstance();
        if (ctx != null) {
          Map sessionState = ctx.getExternalContext().getSessionMap();
          user = (String)sessionState.get("LOGGEDINUSER");
        }
        return  user != null ? new String[]{user} : null;
    }

}
 
 
Application/Project Settings
1. Right click on the ViewController Project
    select ADF View
     Check "Enable User Customizations"
     Select Radio "Across Sessions using MDS"
2. Open adf-config.xml  in the Overview View
In the MDS Configuration Tab
    Click the Add(+) button in Customizations Configurations match Path = "/" and select the Class you just created “a.b.c.MyUserCC”
In the view Tab
    Tags
          Select the tags and the attributes on the tags you want MDS to be enabled on in the application.
 
JSPX/JSFF UI component  Settings
Go to the component you want MDS to work.  Change the attribute persist="ALL" for all properties to work
if you dont want some of them use  dontPersist="displayIndex frozen" (You can use all features you want seperated by a space in both persist and dontPersist attribute. )
























Thursday, August 23, 2012

Coherence Management Extensions (Managing Coherence at runtime)


To Enable Coherence to be managed at runtime Add the below to JVM startup when starting coherence.
-Dcom.sun.management.jmxremote -Dtangosol.coherence.management=all -Dtangosol.coherence.management.remote=true -Dcom.sun.management.jmxremote.port=7772 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"

You can use any JMX browsers like Jrockit mission control or JConsole to actually look at cluster details, caches etc
image

Coherence Client using TCP Extend


There are multiple ways a client can connect to a coherence cluster. TCP Extend is one of them.

Server side Setup:

It is recommended to have a separate coherence instance for a TCP Proxy that doesn’t hold data. We can have a separate Coherence instance by setting this parameter tangosol.coherence.distributed.localstorage=false.
You can make a copy of the existing coherence-cache-config.xml and add the lines marked in Red 
 
proxy-coherence-cache-config.xml
<?xml version="1.0" ?>
<cache-config xmlns:xsi=
http://www.w3.org/2001/XMLSchema-instance             xmlns=http://xmlns.oracle.com/coherence/coherence-cache-config”             xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-cache-config coherence-cache-config.xsd">  <scope-name>TestCacheScope</scope-name>
  <defaults>
    <serializer>pof</serializer>
  </defaults>
  <caching-scheme-mapping>
    <cache-mapping>
      <cache-name>distributed-test</cache-name>
      <scheme-name>distributed-default</scheme-name>
      <init-params>
        <init-param>
          <param-name>size-limit</param-name>
          <param-value>50000</param-value>
        </init-param>
      </init-params>
    </cache-mapping>
  </caching-scheme-mapping>
  <caching-schemes>
    <distributed-scheme>
      <scheme-name>distributed-default</scheme-name>
      <service-name>DistributedCache</service-name>
      <thread-count>5</thread-count>
      <backup-count>1</backup-count>
      <backup-storage>
        <type>file-mapped</type>
        <initial-size>1M</initial-size>
        <maximum-size>5G</maximum-size>
        <directory>/coherence/backup</directory>
      </backup-storage>
      <backing-map-scheme>
        <overflow-scheme>
          <scheme-name>LocalMemoryWithDiskOverflow</scheme-name>
          <front-scheme>
            <local-scheme>
             <high-units>300000</high-units>
            </local-scheme>
          </front-scheme>
          <back-scheme>
            <external-scheme>
              <scheme-name>DiskScheme</scheme-name>
              <nio-file-manager>
                <initial-size>1MB</initial-size>
                <maximum-size>1024MB</maximum-size>
                <directory>/coherence/backup</directory>
              </nio-file-manager>
            </external-scheme>
          </back-scheme>
        </overflow-scheme>
      </backing-map-scheme>
      <autostart>true</autostart>
    </distributed-scheme>
    <proxy-scheme>
      <service-name>ExtendTcpProxyService</service-name>
      <thread-count>5</thread-count>
      <acceptor-config>
        <tcp-acceptor>
          <local-address>
            <address>localhost</address>
            <port>9099</port>
          </local-address>
        </tcp-acceptor>
        <!-- Add the below if you use POF -->
        <serializer>
          <instance>
            <class-name>com.tangosol.io.pof.ConfigurablePofContext</class-name>
            <init-params>
              <init-param>
                <param-type>String</param-type>
                <param-value>pof-config.xml</param-value>
              </init-param>
            </init-params>
          </instance>
        </serializer>
      </acceptor-config>
      <autostart>true</autostart>
    </proxy-scheme>
  </caching-schemes>
</cache-config>


Optionally make a copy of your existing tangosol coherence override xml and change tangosol.coherence.role to ProxyServer as illustrated below. If you don’t change the override.xml when starting the proxy use the original tangosol coherence override .xml as defined for the data caches

proxy-tangasol-coherence-override.xml
<?xml version="1.0" ?>
<coherence xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
           xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config"
           xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-operational-config coherence-operational-config.xsd">  <cluster-config>
    <member-identity>
      <cluster-name system-property="tangosol.coherence.cluster">OperDataCluster</cluster-name>
      <machine-name system-property="tangosol.coherence.machine">coherence1</machine-name>
      <process-name system-property="tangosol.coherence.process">CoherenceProxyServer</process-name>
      <role-name system-property="tangosol.coherence.role">ProxyServer</role-name>
    </member-identity>
    <unicast-listener>
      <address system-property="tangosol.coherence.localhost">localhost</address>
      <port system-property="tangosol.coherence.localport">8088</port>
      <port-auto-adjust system-property="tangosol.coherence.localport.adjust">true</port-auto-adjust>
    </unicast-listener>
    <multicast-listener>
      <address system-property="tangosol.coherence.clusteraddress">224.4.0.255</address>
      <port system-property="tangosol.coherence.clusterport">3060</port>
      <time-to-live system-property="tangosol.coherence.ttl">3</time-to-live>
      <join-timeout-milliseconds>30000</join-timeout-milliseconds>
      <multicast-threshold-percent>25</multicast-threshold-percent>
    </multicast-listener>
  </cluster-config>
  <logging-config>
    <destination system-property="tangosol.coherence.log">stdout</destination>
    <severity-level system-property="tangosol.coherence.log.level">9</severity-level>
  </logging-config>
</coherence>



Starting the proxy 

java -server -Dtangosol.coherence.override=proxy-tangasol-coherence-override.xml -Dtangosol.coherence.distributed.localstorage=false -Dtangosol.coherence.cacheconfig=proxy-coherence-cache-config.xml -cp "$COHERENCE_HOME/lib/coherence.jar com.tangosol.net.DefaultCacheServer

Client Side Setup:

On the client side you need a tangosol.coherence.cacheconfig where you define TCP Extend proxy and invocation service
client-tangasol-cache-config.xml
<?xml version="1.0"?>
<cache-config xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
              xmlns="http://xmlns.oracle.com/coherence/coherence-cache-config"
              xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-cache-config          coherence-cache-config.xsd">
  <scope-name>TestCacheScope</scope-name>
  <caching-scheme-mapping>
    <cache-mapping>
      <cache-name>distributed-*</cache-name>
      <scheme-name>extend-near</scheme-name>
    </cache-mapping>
  </caching-scheme-mapping>
  <caching-schemes>
    <near-scheme>
      <scheme-name>extend-near</scheme-name>
      <front-scheme>
        <local-scheme>
          <scheme-name>localCache</scheme-name>
          <high-units>1000</high-units>
        </local-scheme>
      </front-scheme>
      <back-scheme>
        <remote-cache-scheme>
          <scheme-ref>extend-dist</scheme-ref>
        </remote-cache-scheme>
      </back-scheme>
      <invalidation-strategy>all</invalidation-strategy>
    </near-scheme>
    <remote-cache-scheme>
      <scheme-name>extend-dist</scheme-name>
      <service-name>ExtendTcpCacheService</service-name>
      <initiator-config>
        <tcp-initiator>
          <remote-addresses>
            <socket-address>
              <address>SERVERS IP</address>
              <port>9099</port>
            </socket-address>
          </remote-addresses>
          <connect-timeout>10s</connect-timeout>
        </tcp-initiator>
        <outgoing-message-handler>
          <request-timeout>60s</request-timeout>
        </outgoing-message-handler>
      </initiator-config>
    </remote-cache-scheme>
    <remote-invocation-scheme>
      <scheme-name>extend-invocation</scheme-name>
      <service-name>ExtendTcpInvocationService</service-name>
      <initiator-config>
        <tcp-initiator>
          <remote-addresses>
            <socket-address>
              <address>SERVERS IP</address>
              <port>9099</port>
            </socket-address>
          </remote-addresses>
          <connect-timeout>10s</connect-timeout>
        </tcp-initiator>
        <outgoing-message-handler>
          <request-timeout>5s</request-timeout>
        </outgoing-message-handler>
      </initiator-config>
    </remote-invocation-scheme>
  </caching-schemes>
</cache-config>

 
Package this in the client WAR or EAR along with coherence.jar  when you run the code