[teiid-commits] teiid SVN: r530 - in trunk/server/src/main/java/com/metamatrix: platform/vm/controller and 1 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Tue Mar 3 11:16:25 EST 2009


Author: rareddy
Date: 2009-03-03 11:16:24 -0500 (Tue, 03 Mar 2009)
New Revision: 530

Modified:
   trunk/server/src/main/java/com/metamatrix/platform/registry/ClusteredRegistryState.java
   trunk/server/src/main/java/com/metamatrix/platform/registry/ServiceRegistryBinding.java
   trunk/server/src/main/java/com/metamatrix/platform/registry/VMMonitor.java
   trunk/server/src/main/java/com/metamatrix/platform/vm/controller/ServerEvents.java
   trunk/server/src/main/java/com/metamatrix/server/ServerGuiceModule.java
Log:
TEIID-309: JBoss core cache does not automatically update the objects that are put in the cache; to do that you would either use pojo cache, or manually update them. Since switch to Pojo cache is more intrusive, I opted use updating of the object in the cache. Typically only the objects in the cache are updated, when/if their state has changed.

Modified: trunk/server/src/main/java/com/metamatrix/platform/registry/ClusteredRegistryState.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/registry/ClusteredRegistryState.java	2009-03-03 15:31:10 UTC (rev 529)
+++ trunk/server/src/main/java/com/metamatrix/platform/registry/ClusteredRegistryState.java	2009-03-03 16:16:24 UTC (rev 530)
@@ -78,13 +78,13 @@
 		
 		// only return the active vms
 		VMRegistryBinding binding = (VMRegistryBinding)vmNode.get(VM_CONTROLLER);
-		if (!binding.isAlive()) {
-			throw new CacheNodeNotFoundException("VM Node not found"); //$NON-NLS-1$
+		if (binding == null || !binding.isAlive()) {
+			throw new CacheNodeNotFoundException("VM Node's binding not found or not active"); //$NON-NLS-1$
 		}
 		return vmNode;
 	}
 		
-	protected void addHost(HostControllerRegistryBinding binding) {
+	protected synchronized void addHost(HostControllerRegistryBinding binding) {
 		String hostName = binding.getHostName().toUpperCase();
 		Cache n = this.cache.addChild(hostName);
 		n.put(NAME, hostName);
@@ -95,11 +95,19 @@
 		this.cache.removeChild(hostName.toUpperCase());
 	}
 	
-	protected void addVM(String hostName, String vmName, VMRegistryBinding vmBinding) throws CacheNodeNotFoundException {
+	protected synchronized void addVM(String hostName, String vmName, VMRegistryBinding vmBinding) throws CacheNodeNotFoundException {
 		Cache vmNode = addVMNode(hostName, vmName);
 		vmNode.put(VM_CONTROLLER, vmBinding);
 	}
 	
+	protected void updateVM(String hostName, String vmName, VMRegistryBinding binding) throws ResourceNotBoundException, CacheNodeNotFoundException {
+		Cache vmNode = getVMNode(hostName, vmName);
+		if (vmNode.get(VM_CONTROLLER) == null) {
+			throw new ResourceNotBoundException(ServicePlugin.Util.getString(ServiceMessages.REGISTRY_0012, hostName+"/"+vmName )); //$NON-NLS-1$
+		}
+		vmNode.put(VM_CONTROLLER, binding);		
+	} 	
+	
 	protected void removeVM(String hostName, String vmName) {
 		try {
 			Cache hostNode = getHostNode(hostName);
@@ -178,7 +186,7 @@
 	}
 	
 	
-	protected void addServiceBinding(String hostName, String vmName, ServiceRegistryBinding binding) throws ResourceAlreadyBoundException, CacheNodeNotFoundException {
+	protected synchronized void addServiceBinding(String hostName, String vmName, ServiceRegistryBinding binding) throws ResourceAlreadyBoundException, CacheNodeNotFoundException {
 		Cache services = getServices(hostName, vmName);
 
 		// check if this service already exists
@@ -190,6 +198,18 @@
         services.put(binding.getServiceID(), binding);
 	}
 	
+	protected void updateServiceBinding(String hostName, String vmName, ServiceRegistryBinding binding) throws ResourceNotBoundException, CacheNodeNotFoundException {
+		Cache services = getServices(hostName, vmName);
+
+		// check if this service already exists
+		ServiceRegistryBinding existing = (ServiceRegistryBinding)services.get(binding.getServiceID());
+        if (existing == null) {
+        	throw new ResourceNotBoundException(ServicePlugin.Util.getString(ServiceMessages.REGISTRY_0011, binding.getServiceID() ));
+        }
+		
+        services.put(binding.getServiceID(), binding);	
+   }	
+	
 	public ServiceRegistryBinding getServiceBinding(String hostName, String vmName, ServiceID serviceId ) throws ResourceNotBoundException {
 		ServiceRegistryBinding binding;
 		try {
@@ -296,5 +316,5 @@
 		for(RegistryListener l:this.listeners) {
 			l.registryChanged();
 		}		
-	} 
+	}
 }

Modified: trunk/server/src/main/java/com/metamatrix/platform/registry/ServiceRegistryBinding.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/registry/ServiceRegistryBinding.java	2009-03-03 15:31:10 UTC (rev 529)
+++ trunk/server/src/main/java/com/metamatrix/platform/registry/ServiceRegistryBinding.java	2009-03-03 16:16:24 UTC (rev 530)
@@ -63,8 +63,8 @@
 		        throw err.getTargetException();
 		    }
 		    
+		    ServiceRegistryBinding.this.setInitException(proxiedService.getInitException());
 		    ServiceRegistryBinding.this.updateState(proxiedService.getCurrentState());
-		    ServiceRegistryBinding.this.setInitException(proxiedService.getInitException());
 		    return returnObj;
 		}
 	}
@@ -119,6 +119,8 @@
     
     private transient MessageBus messageBus;
     
+    private transient boolean dirty;
+    
     /**
      * Create new ServiceRegistryInstance
      *
@@ -246,8 +248,11 @@
     }
     
     public void updateState(int state) {
-        this.currentState = state;
-        this.stateChangeTime = new Date();
+    	if (this.currentState != state) {
+	        this.currentState = state;
+	        this.stateChangeTime = new Date();
+	        this.dirty = true;
+    	}
     }
    
     private Collection buildQueueNames(ServiceInterface si) {
@@ -305,8 +310,16 @@
 	}
 	
 	public void markServiceAsBad() {
-		this.currentState = ServiceState.STATE_FAILED;
 		setService(null);
+		updateState(ServiceState.STATE_FAILED);
 	}
+
+	public void setDirty(boolean dirty) {
+		this.dirty = dirty;
+	}
+
+	public boolean isDirty() {
+		return dirty;
+	}
 }
 

Modified: trunk/server/src/main/java/com/metamatrix/platform/registry/VMMonitor.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/registry/VMMonitor.java	2009-03-03 15:31:10 UTC (rev 529)
+++ trunk/server/src/main/java/com/metamatrix/platform/registry/VMMonitor.java	2009-03-03 16:16:24 UTC (rev 530)
@@ -91,15 +91,23 @@
     		@Override
     		public void run() {
     			List<VMRegistryBinding> vmBindings = VMMonitor.this.registry.getVMs(null);
+
     			for (VMRegistryBinding binding: vmBindings) {
-	                try {
-	                    VMControllerInterface vm = binding.getVMController();
+                    VMControllerInterface vm = binding.getVMController();
+                    boolean alive = binding.isAlive();
+	                
+                    try {
 	                    vm.ping();
 	                    binding.setAlive(true);
 	                } catch (ServiceException e) {
 	                	// mark as not alive, then no services will be pinged from this vm
 	                	binding.setAlive(false);
 	                }
+	                
+	                // if the vmstate changed then, update the registry.
+	                if (alive != binding.isAlive()) {
+	                	vmUpdated(binding);
+	                }
 	            }
     		}
     	}, POLLING_INTERVAL_DEFAULT, POLLING_INTERVAL_DEFAULT);
@@ -111,16 +119,23 @@
         	public void run() {
         		List<ServiceRegistryBinding> bindings = registry.getServiceBindings(hostName, vmId.toString());
                 for (ServiceRegistryBinding binding:bindings) {
-            		try {
+
+                	ServiceInterface si = binding.getService();
+                	try {
             			// when service in stopped state; this will be null
             			// if shut down there will not be a binding for it.
-            			ServiceInterface si = binding.getService();
             			if(si != null) {
             				binding.getService().checkState();
             			}
     				} catch (ServiceStateException e) {
     					// OK to throw up, service will capture the error to logs.
     				}
+    				
+    				// the state of the service changed, then update the cache.
+    				if (binding.isDirty()) {
+    					serviceUpdated(binding);
+    					binding.setDirty(false);
+    				}
                 }
         	}
         }, pollingIntervel, pollingIntervel);
@@ -158,4 +173,29 @@
 		this.registry.removeVM(hostName, vmId.toString());		
 		LogManager.logDetail(LogCommonConstants.CTX_CONTROLLER, "VM Removed:"+id); //$NON-NLS-1$
 	}
+
+	@Override
+	public void serviceUpdated(ServiceRegistryBinding binding) {
+		try {
+			this.registry.updateServiceBinding(binding.getHostName(), binding.getServiceID().getVMControllerID().toString(), binding);
+			LogManager.logDetail(LogCommonConstants.CTX_CONTROLLER, "Service updated:"+binding.getServiceID()); //$NON-NLS-1$
+		} catch(CacheNodeNotFoundException e) {
+			LogManager.logError(LogCommonConstants.CTX_CONTROLLER, e, "Failed to add service:"+binding.getServiceID()); //$NON-NLS-1$
+		} catch (ResourceNotBoundException e) {
+			LogManager.logWarning(LogCommonConstants.CTX_CONTROLLER, "Service not exist:"+binding.getServiceID()); //$NON-NLS-1$
+		}
+	}
+
+	@Override
+	public void vmUpdated(VMRegistryBinding binding) {
+		try {
+			this.registry.updateVM(binding.getHostName(), binding.getVMControllerID().toString(), binding);
+			LogManager.logDetail(LogCommonConstants.CTX_CONTROLLER, "VM Added:"+binding.getVMControllerID()); //$NON-NLS-1$
+		} catch (CacheNodeNotFoundException e) {
+			LogManager.logError(LogCommonConstants.CTX_CONTROLLER, e, "Failed to add VM:"+binding.getVMControllerID()); //$NON-NLS-1$
+			throw new MetaMatrixRuntimeException("Failed to add VM:"+binding.getVMControllerID()); //$NON-NLS-1$
+		} catch(ResourceNotBoundException e) {
+			LogManager.logWarning(LogCommonConstants.CTX_CONTROLLER, "VM does not exist:"+binding.getVMControllerID()); //$NON-NLS-1$
+		}
+	}
 }

Modified: trunk/server/src/main/java/com/metamatrix/platform/vm/controller/ServerEvents.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/vm/controller/ServerEvents.java	2009-03-03 15:31:10 UTC (rev 529)
+++ trunk/server/src/main/java/com/metamatrix/platform/vm/controller/ServerEvents.java	2009-03-03 16:16:24 UTC (rev 530)
@@ -32,8 +32,11 @@
 	
 	void vmRemoved(VMControllerID id);
 	
+	void vmUpdated(VMRegistryBinding binding);
+	
 	void serviceAdded(ServiceRegistryBinding binding);
 	
 	void serviceRemoved(ServiceID id);
 	
+	void serviceUpdated(ServiceRegistryBinding binding);
 }

Modified: trunk/server/src/main/java/com/metamatrix/server/ServerGuiceModule.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/ServerGuiceModule.java	2009-03-03 15:31:10 UTC (rev 529)
+++ trunk/server/src/main/java/com/metamatrix/server/ServerGuiceModule.java	2009-03-03 16:16:24 UTC (rev 530)
@@ -83,7 +83,7 @@
 		bindConstant().annotatedWith(Names.named(Configuration.VMID)).to(vmID);
 		bind(Host.class).annotatedWith(Names.named(Configuration.HOST)).toInstance(host);
 		bindConstant().annotatedWith(Names.named(Configuration.CLUSTERNAME)).to(systemName);
-		bindConstant().annotatedWith(Names.named(Configuration.LOGFILE)).to(StringUtil.replaceAll(host.getFullName(), ".", "_")+this.vmName+".log"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+		bindConstant().annotatedWith(Names.named(Configuration.LOGFILE)).to(StringUtil.replaceAll(host.getFullName(), ".", "_")+"_"+this.vmName+".log"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
 		bindConstant().annotatedWith(Names.named(Configuration.LOGDIR)).to(host.getLogDirectory());
 				
 		Names.bindProperties(binder(), CurrentConfiguration.getInstance().getProperties());




More information about the teiid-commits mailing list