Monday, April 27, 2009

My Sis' reasons why BJP is better

Nuclear deal:
The stage was set by Atal. Anyone could have done it. It was done because US was willing to do it. Congress did not do anything special that BJP could not have done.
Kandahar episode:
Did anyone ask Congress what would they have done if Rahul Baba was in the same plane?
Mumbai terror attack:
No one suppose to talk about CS Station where 57 people died. Everyone is talking about Taj which was at the center of international attention. Are lives of common people cheaper? What was their preparedness? How come a few terrorists walked free for so many hours and held the entire nation hostage for three days? Why was response so late?
Kasab/Afjal Guru:
Why is Afjal not hanged yet when Supreme Court has already convicted him? Why is plea bargain still pending? Why has home ministry not forwarded anything to the President's office yet? About Kasab - He is captured on video. If he is found to be 17 would they keep him in a juvenile detention center?
Zero leadership:
India needs a strong leadership. South Asia is in mess. India needs a leader like Indira Gandhi an internationally aggressive personality not a weak person who seeks permission from a family to do anything.
Rahul as PM - You kidding me?
Congress is trying to project Rahul or Priyanka as a Prime Ministerial candidate. This cannot be accepted.
National progress:
BJP and Congress are the only two parties who would not slow down the national progress. Its about the speed of it. Third front is a mess. They don't fight on issues but do seat calculations. Third front has stronger allies of Congress and they impede our progress.

Wednesday, April 22, 2009

Push Replication - You know it alright

So you have heard about it alright here, here, here, this one too, here and even here and of course a hero of numerous talks at NYSIG, UKSIG and more. I have had opportunities to work on multi-cluster Coherence solutions at many client locations and also be part of a project whose one member is an active contributor to Push Replication. So what new do I have to bring on table? A working example for Incubator junkies for one. If you have followed Brian Oliver's write-up at Push Replication page I am sure you already know how to set this up and get running in just a few minutes. So I thought to spice it up a little. So lets build the following:
Setting up Active-Activen clusters
Active/Active is pretty similar to how we set up Active/Passive clusters but it needs some special classes to be used. First, make sure SafePublishingCacheStore is configured in the cache config and as we register a publisher we use SafeLocalCachePublisher instead of LocalCachePublisher.

Making use of introduce element in cache configuration

Start using introduce tag while writing coherence cache config. This is one of the very useful features introduced in coherence common incubator pattern. introduce tag allows us re-use of common cache configurations and is as simple as:
<cache-config>
<introduce-cache-config file="coherence-pushreplicationpattern-cache-config.xml"/>
</cache-config>


Dynamic subscription of subscriber clusters
One architecture that Push replication supports and possibly the most popular one as well, is a hub-n-spoke model. In the hub-n-spoke model not only the spoke clusters know about the hub but the hub knows about all the clusters on the spokes as well at least at the time of deployment. This "knowledge" of the other cluster is in shape of a set of remote-cache-schemes. Recently I came across a requirement where the number of spoke clusters were not known at the time of deployment. This ever expanding subscriber cluster introduces new challenges to Push replication deployments. Coherence is all about 100% up time and stopping the hub every time a new subscriber cluster joins, is not a preferable deployment. So lets introduce how new clusters can dynamically join the hub so that hub does not know about the subscriber but subscriber knows about the hub.

Lets start with some cache configurations and how it will look in a production environment. The following samples are part of a proof of concept and there is a scope of a few tweakings.

Coherence Cache Configuration on the hub
<?xml version="1.0" encoding="windows-1252" ?>
<!DOCTYPE cache-config SYSTEM "cache-config.dtd">
<cache-config>
 <introduce-cache-config file="coherence-pushreplicationpattern-cache-config.xml" />
  <caching-scheme-mapping>
  </caching-scheme-mapping>
 <caching-schemes>
     <proxy-scheme>
         <scheme-name>proxy-scheme</scheme-name>
         <service-name>ProxyCacheScheme</service-name>
         <acceptor-config>
             <tcp-acceptor>
                 <local-address>
                     <address>localhost</address>
                     <port>20000</port>
                     <reusable>true</reusable>
                 </local-address>
                 <keep-alive-enabled>true</keep-alive-enabled>
             </tcp-acceptor>
          </acceptor-config>
         <autostart>true</autostart>
     </proxy-scheme>            
 </caching-schemes>
</cache-config>
Hmm... The only configuration the hub cache config has is proxy-scheme. The hub does not know anything about who the subscribers will be. Will explain later how it will be done, scroll down.

coherence-pushreplicationpattern-cache-config.xml
Its pretty much the same as seen when you download the push replication project, just replace PublishingCacheStore with SafePublishingCacheStore.

Subscriber Cluster Cache Configuration
Cache configuration deployed on the subscriber cluster looks a little more complete as subscriber knows about which hub it has to connect to. The configuration looks like:
<cache-config>
 <introduce-cache-config file="coherence-pushreplicationpattern-cache-config.xml" />
 
 <caching-scheme-mapping>
 </caching-scheme-mapping>
 <caching-schemes>
     <proxy-scheme>
         <scheme-name>proxy-scheme</scheme-name>
         <service-name>ProxyCacheScheme</service-name>
         <acceptor-config>
             <tcp-acceptor>
                 <local-address>
                     <address>localhost</address>
                     <port>9099</port>
                     <reusable>true</reusable>
                 </local-address>
                 <keep-alive-enabled>true</keep-alive-enabled>
             </tcp-acceptor>            
         </acceptor-config>
         <autostart>true</autostart>        
     </proxy-scheme>    
 
     <remote-invocation-scheme>
         <scheme-name>RemoteSiteInvocationService</scheme-name>
         <service-name>RemoteSiteInvocationService</service-name>
         <initiator-config>
             <tcp-initiator>
                 <remote-addresses>
                     <socket-address>
                         <address>localhost</address>
                         <port>20000</port>
                     </socket-address>
                 </remote-addresses>
             </tcp-initiator>
         </initiator-config>    
     </remote-invocation-scheme>
 
     <invocation-scheme>
         <scheme-name>invocation-scheme</scheme-name>
         <service-name>InvocationService</service-name>
         <autostart>true</autostart>
     </invocation-scheme>
 </caching-schemes>

</cache-config>


Dynamic Registration of Subscriber Cluster
The following example is a very scaled down sample tuned to be run on a single machine. Change it as needed. Also the following class should be made a MBean so that it can be executed from a JMX console.
Run:
java -Dtangosol.coherence.distributed.localstorage=false -Dtangosol.coherence.clusteraddress=<subscriber-multicast-ip> -Dtangosol.coherence.cacheconfig=subscriber-cache-config.xml PushReplicationClient <proxy-port> <subscriber-name>
public class PushReplicationClient implements Serializable {

 public PushReplicationClient() {
 }

 public static void main(String[] args) {
     PushReplicationClient pC = new PushReplicationClient();
     String cacheName = "publishing-cache";
     String remoteServiceName = args[1];
     NamedCache nCache = CacheFactory.getCache(cacheName);
     PublisherRegistrationTask rTask =
                          pC.new PublisherRegistrationTask(cacheName,
                                        remoteServiceName, remoteServiceName);
     InvocationService iS =
         (InvocationService) CacheFactory.getService("RemoteSiteInvocationService");
     iS.query(pC.new SubscriberTask(remoteServiceName, Integer.parseInt(args[0])),
              null);
     iS.query(rTask, null);
     Member sM = CacheFactory.getCluster().getOldestMember();
     InvocationService isLocal =
         (InvocationService) CacheFactory.getService("InvocationService");
     rTask = pC.new PublisherRegistrationTask(cacheName,
                          "RemoteSiteInvocationService", remoteServiceName);
                                                                              
     isLocal.execute(rTask, new HashSet(Collections.singletonList(sM)), null);

 }

 private class PublisherRegistrationTask implements Invocable {

     private String cacheName;
     private String serviceName;
     private String publisherName;

     public PublisherRegistrationTask(String cacheName, String serviceName,
                                      String publisherName) {
         this.cacheName = cacheName;
         this.serviceName = serviceName;
         this.publisherName = publisherName;
     }

     public void init(InvocationService invocationService) {

     }

     public void run() {
         PushReplicationManager pM =
             DefaultPushReplicationMananger.getInstance();
         BatchPublisher batchPublisher =
             new RemoteInvocationPublisher(serviceName,
                                           new BatchPublisherAdapter(
                                           new SafeLocalCachePublisher(cacheName)),
                                           true, 10000, 100, 10000, 5);
         pM.registerBatchPublisher(cacheName, publisherName,
                                   batchPublisher);
     }

     public Object getResult() {
         return null;
     }

 }

 private class SubscriberTask implements Invocable {

     private String serviceName;
     private int port;

     public SubscriberTask(String serviceName, int port) {
         this.serviceName = serviceName;
         this.port = port;
     }

     public void init(InvocationService invocationService) {

     }

     public void run() {
         ConfigurableCacheFactory factory =
             CacheFactory.getConfigurableCacheFactory();
         XmlElement root = factory.getConfig();
         XmlElement cS = root.findElement("caching-schemes");
         XmlElement riS = cS.addElement("remote-invocation-scheme");
         riS.addElement("scheme-name").setString(serviceName);
         riS.addElement("service-name").setString(serviceName);
         XmlElement iC = riS.addElement("initiator-config");
         XmlElement tI = iC.addElement("tcp-initiator");
         XmlElement rA = tI.addElement("remote-addresses");
         XmlElement sA = rA.addElement("socket-address");
         sA.addElement("address").setString("localhost");
         sA.addElement("port").setInt(port);
         factory.setConfig(root);
         System.out.println(cS);
     }

     public Object getResult() {
         return null;
     }

 }

}

There are three parts of this class:
  1. Updates the cache configuration deployed on the hub to register itself.
  2. Registers a Publisher on the hub so that changes made in the hub is pushed to this subscriber cluster.
  3. Registers a publisher in the local cluster so that the replication is in Active-Active mode. Changes made in the subscriber cluster also is pushed to the hub's cache and thereafter to other subscriber clusters.
Execute this program for each subscriber cluster that needs to join the hub. Change the subscriber cache configuration accordingly. While I was developing this sample I found an issue in SafeLocalCachePublisher as it was missing a default constructor. A JIRA has been opened and will be fixed in the next Incubator release. In the meantime download the push replication source code and add a default constructor in SafeLocalCachePublisher. So thats pretty much it. Running geographically distributed dynamically subscribed multi-clusters in a hub-n-spoke architecture in less than 10 minutes and then staying up 100% of the time. A complete project with an MBean can be downloaded from Dynamic Push Replication Subscription page. Enjoy!

Sunday, April 19, 2009

एक शेर..

किताबें पढ़ पढ़ के सोचा था कि हाफिज़ मैं बनुंगा इक दिन,
खुदा रग रग में रहता है खोजता मैं किताबों में!
कि सोचा था मुझे बस मिल गई ताबीज़ आयत की,
भटकता फ़िर भी रहता हूँ इन आइनों की गलियों में!!

Friday, April 17, 2009

Securing a Coherence Cache

Coherence is a data source and the question is if we can secure it so that only authorized users/applications can access it. A sample custom named cache based solution is already available Here. Based on this example I have streamlined and simplified it's integration a little so that cache configuration is simpler and scope of security provider is taken out of Coherence. The entire project is available at Securing a Coherence Cache. [Part II is at http://ezsaid.blogspot.com/2009/10/integrating-ldap-with-coherence.html]

Following are some simplifications:

  1. Add a new XML Element (<entitled>) to enable a cache scheme for security. The configuration will look like the following:
    <distributed-scheme>
    <scheme-name>distributed-scheme</scheme-name>
    <service-name>DistributedCache</service-name>
    <backing-map-scheme>
    <local-scheme></local-scheme>
    </backing-map-scheme>
    <autostart>true</autostart>
    <entitled>
    <security-provider>MySecurityProvider</security-provider>
    </entitled>

    </distributed-scheme>
  2. A new ConfigurableCacheFactory. It's setConfig looks like:
        public void setConfig(XmlElement xmlConfig) {
    // -- Find all the caches for which entitled is set to true
    // -- Fild all cache names that has the scheme for which
    // -- entitled tag is defined
    // -- Replace the scheme name to a class-scheme with Entitled
    // -- cache
    // -- Find all the cache schemes with entitled set to true
    Map map = findEntitledSchemes(xmlConfig);
    XmlElement csM =
    xmlConfig.findElement("caching-scheme-mapping");
    Iterator cMs = csM.getElements("cache-mapping");
    XmlElement cM = null;
    while (cMs.hasNext()) {
    cM = (XmlElement) cMs.next();
    String schemeName =
    cM.findElement("scheme-name").getString();
    if (map.containsKey(schemeName)) {
    cM.findElement("scheme-name").setString("entitled-scheme");
    XmlElement iPs = cM.addElement("init-params");
    XmlElement iP = iPs.addElement("init-param");
    iP.addElement("param-name").setString("security-provider");
    iP.addElement("param-value").setString(map.get(schemeName));
    }
    }

    XmlElement rCS =
    XmlHelper.findElement(xmlConfig, "//caching-schemes");
    XmlElement cS = rCS.addElement("class-scheme");
    cS.addElement("scheme-name").setString("entitled-scheme");
    cS.addElement("class-name").setString(
    EntitledNamedCache.class.getName());
    XmlElement iPs = cS.addElement("init-params");

    XmlElement iP = iPs.addElement("init-param");
    iP.addElement("param-type").setString("string");
    iP.addElement("param-value").setString("{cache-name}");

    XmlElement iP2 = iPs.addElement("init-param");
    iP2.addElement("param-type").setString("string");
    String cache_config =
    System.getProperty("tangosol.coherence.cacheconfig");
    if (cache_config == null) {
    cache_config = FILE_CFG_CACHE;
    }
    iP2.addElement("param-value").setString(cache_config);

    XmlElement iP3 = iPs.addElement("init-param");
    iP3.addElement("param-type").setString("string");
    iP3.addElement("param-value").setString("{security-provider}");

    super.setConfig(xmlConfig);
    }
  3. A new interface to implement. Implement SecurityProvider interface and configure it as a security-provider in the cache configuration.
    public interface SecurityProvider {
    public boolean checkAccess (Subject subject);
    }
And thats all you need. Download the complete code from Securing a Coherence Cache. Enjoy!

Wednesday, April 15, 2009

India - Go and Vote

My sister a Civil Servant has been ultra busy for past two months - 7 days a week, 9 hrs a day, no vacation no public holidays to get the election logistics in her city ready. Keeping records, Computerization, testing each electronic voting machine and tons and tons of reviews and tests. So much effort has gone into making this noble right succeed. People who do not know it takes a lot of energy, effort and your tax money to conduct Elections so its your duty to go out and vote. Choose one and the right one, the one you believe is right to fulfill your aspirations. State can not afford to conduct elections again and again so choose wisely that the government is formed for full five years. Slap those who say "None of the above" should be an option on a ballot paper. Neither the government, nor the state instrument nor you can afford it. Listen to your inner voice and Just go and vote. Make Indian democracy a success again.

Saturday, April 11, 2009

Why is third front a disease India needs to get rid of?

Third front as it stands today constitutes of a bunch of parties that have aligned themselves with either of two main political platforms in the past. BJD and TDP with BJP, SP, RJD and Left with Congress, and so is AIADMK and switching their coalition for the other at a convenient time. Make no mistake some of these parties are great regional powers but their agenda is at a state level but unfortunately with a spineless national policy. These are also the parties that most likely will engage in horse trading at the end of elections. NDA has announced Advani and UPA Manmohan Singh as its Prime Ministerial candidates. Who is from this gutless third front? India has suffered most when we saw four/five PMs one after another by this loosely coupled groups of regional parties. India can not afford it no more. The essence of a successful Republic is strong representation of regional expectations. Either provide a third front with a totally different ideological agenda or just abolish it. India cannot afford to let these parties steal away their regional parliamentary seats and then play Ministry trading in the center and pull the nation to its political dark ages. Whatever they say their own agenda is no different from the common minimum program of either UPA or NDA then why waste our precious time? This no-agenda-political-front is a disease that India has to soon get rid of.

Wednesday, April 08, 2009

Disabling Coherence Cache

Another simple problem: How do I control if certain or all Cache operations should be disabled? By default it is not possible and need some custom coding... How? As usual lets create a cache config..

<cache-config>
<caching-scheme-mapping>
<cache-mapping>
<cache-name>ControllerCache</cache-name>
<scheme-name>some-dist</scheme-name>
</cache-mapping>
<cache-mapping>
<cache-name>ControlledCache</cache-name>
<scheme-name>with-rw-bm</scheme-name>
</cache-mapping>
</caching-scheme-mapping>
<caching-schemes>
<distributed-scheme>
<scheme-name>with-rw-bm</scheme-name>
<service-name>unlimited-partitioned</service-name>
<backing-map-scheme>
<read-write-backing-map-scheme>
<scheme-ref>base-rw-bm</scheme-ref>
</read-write-backing-map-scheme>
</backing-map-scheme>
<autostart>true</autostart>
</distributed-scheme>
<read-write-backing-map-scheme>
<scheme-name>base-rw-bm</scheme-name>
<class-name>ControllerBackingMap</class-name>
<internal-cache-scheme>
<local-scheme/>
</internal-cache-scheme>
</read-write-backing-map-scheme>
</caching-schemes>
</cache-config>
Now lets create the ControllerBackingMap...
public class ControllerBackingMap extends ReadWriteBackingMap 
implements XmlConfigurable, MapListenerSupport.SynchronousListener {
private XmlElement m_config;
private volatile boolean isOkay = true;

public ControllerBackingMap (.,.,.,...) {
super (.,.,.,...);
}
...
public void setConfig (XmlElement xmlElement) {
...
// -- Or pass the cache name as a parameter
NamedCache nCache = CacheFactory.getCache ("ControllerCache");
nCache.addMapListener (this);
}

public void entryInserted (MapEvent evt) {
if (evt.getNewValue() == ....) {
isOkay = false;
}
}

public Object put(final Object oKey, final Object oValue) {
???????
}
....
}
Now what? Lets say we want to disable any Cache puts if something has been inserted in the ControllerCache.. Of course expand it to any specifics keeping the controller cache model. The put () method will look like:
   public Object put(final Object oKey, final Object oValue) {
if (!isOkay) {
throw new RuntimeException("Operation currently blocked");
}
return super.put(oKey, oValue);
}
So here you go, Enjoy!

Monday, April 06, 2009

Why Oracle-Sun together makes more sense

For me the marriage is between two who can make each other complete. For Sun wouldn't it make more sense to marry a Devdas who is just made for you and not to some rich Sheikh who has a Harem of wives? Oracle, the Devdas misses an Operating System and a hardware business that Sun could bring and Sun will get a loving husband who will support her, share each others pain and provide a massive software platform to grow. A marriage of two where one does not kill the talents of the other because he had his own to push. A lady who comes with her own kitchen and utensils married to a farmer who grows his own vegetables. I see just a perfect marriage.

Thursday, April 02, 2009

Varun in Tytler out

Jagdish Tytler has been acquitted for the lack of evidence for his role in 1984 riots in Delhi against Sikhs after Indira Gandhi's assassination. This remains one of the few blots that India had to live with for decades and as a nation that it remained ashamed of. Tytler may not have any role or was mistaken or framed, I don't know but by what victims had to say or saw it seemed very much likely that he did play some role. Ironical, isn't it? So a man has been acquitted even though people saw him participating and directing mobs but Varun Gandhi has been slapped NSA because he said what he should not have said. Both are equally reprehensible but harsh treatment for one and letting the other go does not sound right, does it? It is said justice delayed is justice denied. 25 years gives enough time for powerful figures to coarse the evidences to make them doubtful to be not be able to be used against them. Could this be the case? Either way, Its lucky for him to be living under the free sky and fresh air but if he was responsible and still left with any shame or guilt he should leave all political and public office. If he was not responsible then I congratulate him on his acquittal. May the victim's soul rest in peace and who ever was responsible should soon meet them in heaven.