incubator-kato-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spo...@apache.org
Subject svn commit: r826984 - in /incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview: api/ impl/
Date Tue, 20 Oct 2009 07:48:12 GMT
Author: spoole
Date: Tue Oct 20 07:48:11 2009
New Revision: 826984

URL: http://svn.apache.org/viewvc?rev=826984&view=rev
Log:
Added new code to store javaview info in a database

Added:
    incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/IJavaClass.java
    incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/IJavaClassLoader.java
    incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/IJavaInstance.java
    incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/IJavaView.java
    incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/QueryResult.java
    incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/Datastore.java
    incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaClassImpl.java
    incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaClassLoaderImpl.java
    incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaInstanceImpl.java
    incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaViewBuilder.java
    incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/SQLDatastore.java
Removed:
    incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/Group.java
    incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/JavaView.java
    incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/VJavaClassLoader.java
    incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/PersistentStore.java
    incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/PersistentStoreBuilder.java
Modified:
    incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/JavaInstance.java
    incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaClassLoaderHierarchyBuilder.java
    incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaViewImpl.java

Added: incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/IJavaClass.java
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/IJavaClass.java?rev=826984&view=auto
==============================================================================
--- incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/IJavaClass.java
(added)
+++ incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/IJavaClass.java
Tue Oct 20 07:48:11 2009
@@ -0,0 +1,19 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+package org.apache.kato.javaview.api;
+
+public interface IJavaClass {
+
+}

Added: incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/IJavaClassLoader.java
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/IJavaClassLoader.java?rev=826984&view=auto
==============================================================================
--- incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/IJavaClassLoader.java
(added)
+++ incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/IJavaClassLoader.java
Tue Oct 20 07:48:11 2009
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.javaview.api;
+
+import java.util.Set;
+
+public interface IJavaClassLoader {
+
+	public Set<IJavaClassLoader> getParents();
+	public Set<IJavaClassLoader> getChildren();
+}

Added: incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/IJavaInstance.java
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/IJavaInstance.java?rev=826984&view=auto
==============================================================================
--- incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/IJavaInstance.java
(added)
+++ incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/IJavaInstance.java
Tue Oct 20 07:48:11 2009
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.javaview.api;
+
+import javax.tools.diagnostics.runtime.java.JavaField;
+
+public interface IJavaInstance {
+
+
+	 public QueryResult<JavaField> getFields();
+	 
+	 public IJavaClass getJavaClass();
+	 
+	 
+}

Added: incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/IJavaView.java
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/IJavaView.java?rev=826984&view=auto
==============================================================================
--- incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/IJavaView.java
(added)
+++ incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/IJavaView.java
Tue Oct 20 07:48:11 2009
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+package org.apache.kato.javaview.api;
+
+import java.io.IOException;
+
+public interface IJavaView {
+
+	 public QueryResult<IJavaInstance> getInstances() throws IOException;
+
+	public void close();
+	 
+}

Modified: incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/JavaInstance.java
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/JavaInstance.java?rev=826984&r1=826983&r2=826984&view=diff
==============================================================================
--- incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/JavaInstance.java
(original)
+++ incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/JavaInstance.java
Tue Oct 20 07:48:11 2009
@@ -18,5 +18,5 @@
 public interface JavaInstance {
 
 
-	 public Group<JavaField> getFields();
+	 public QueryResult<JavaField> getFields();
 }

Added: incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/QueryResult.java
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/QueryResult.java?rev=826984&view=auto
==============================================================================
--- incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/QueryResult.java
(added)
+++ incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/api/QueryResult.java
Tue Oct 20 07:48:11 2009
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.javaview.api;
+
+import java.io.IOException;
+
+
+public interface QueryResult<T> extends Iterable<T>{
+
+	
+	// Return a subset of type <T> based on the "filter" string
+    // an XPath query.
+	QueryResult<T> filterSet(String filter);
+
+    // Reduce this result set using the filter passed.
+    void applyFilter(String filter);
+
+    // Run a query on the string.
+    QueryResult<?> query(String filter);
+    
+    T getElement(long elementNumber) throws IOException;
+    
+    long getSize() throws IOException;
+}

Added: incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/Datastore.java
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/Datastore.java?rev=826984&view=auto
==============================================================================
--- incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/Datastore.java
(added)
+++ incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/Datastore.java
Tue Oct 20 07:48:11 2009
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+package org.apache.kato.javaview.impl;
+
+import java.io.IOException;
+
+
+public 
+ interface Datastore {
+
+	public void open() throws IOException;
+	
+	void addJavaClassLoader(JavaClassLoaderImpl i);
+
+	
+
+	void addJavaClass(JavaClassImpl clazzImpl);
+
+	JavaClassImpl getJavaClass(long clazzid);
+
+	void addJavaInstance(JavaInstanceImpl impl);
+
+	JavaClassLoaderImpl getJavaClassLoader(long loader);
+
+	public void close() throws IOException;
+}

Added: incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaClassImpl.java
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaClassImpl.java?rev=826984&view=auto
==============================================================================
--- incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaClassImpl.java
(added)
+++ incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaClassImpl.java
Tue Oct 20 07:48:11 2009
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+package org.apache.kato.javaview.impl;
+
+import org.apache.kato.javaview.api.IJavaClass;
+import org.apache.kato.javaview.api.IJavaClassLoader;
+
+class JavaClassImpl implements IJavaClass {
+	 
+	
+	/**
+	 * 
+	 */
+	private final Datastore store;
+	private long id=0;
+	private long loader=0;
+	private String name=null;
+	
+	
+	
+	
+	JavaClassImpl( Datastore store, long id,long loader,String name) {
+		this.store=store;
+		this.id=id;
+		this.loader=loader;
+		this.name=name;
+	
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public IJavaClassLoader getLoader() {
+		return store.getJavaClassLoader(loader);
+	}
+
+	public long getClassID() {
+		return id;
+	}
+
+	public long getLoaderID() {
+		return loader;
+	}
+
+	
+}
\ No newline at end of file

Modified: incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaClassLoaderHierarchyBuilder.java
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaClassLoaderHierarchyBuilder.java?rev=826984&r1=826983&r2=826984&view=diff
==============================================================================
--- incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaClassLoaderHierarchyBuilder.java
(original)
+++ incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaClassLoaderHierarchyBuilder.java
Tue Oct 20 07:48:11 2009
@@ -21,7 +21,9 @@
 import javax.tools.diagnostics.runtime.java.JavaClass;
 import javax.tools.diagnostics.runtime.java.JavaClassLoader;
 
-import org.apache.kato.javaview.api.VJavaClassLoader;
+import org.apache.kato.javaview.api.IJavaClassLoader;
+
+
 
 
 
@@ -93,12 +95,12 @@
 
 	
 
-	public class Loader implements VJavaClassLoader {
+	public class Loader implements IJavaClassLoader {
 	
 		private JavaClassLoader definingLoader=null;
 		private Set<JavaClass> inheritedClasses=new HashSet<JavaClass>();
-		private Set<VJavaClassLoader> kids=new HashSet<VJavaClassLoader>();
-		private Set<VJavaClassLoader> parents=new HashSet<VJavaClassLoader>();
+		private Set<IJavaClassLoader> kids=new HashSet<IJavaClassLoader>();
+		private Set<IJavaClassLoader> parents=new HashSet<IJavaClassLoader>();
 		
 		
 		public String toString() {
@@ -140,7 +142,7 @@
 		
 	
 		
-		public Set<VJavaClassLoader> getParents() {
+		public Set<IJavaClassLoader> getParents() {
 			
 			return parents;
 		}
@@ -161,7 +163,7 @@
 			return definingLoader;
 		}
 		@Override
-		public Set<VJavaClassLoader> getChildren() {
+		public Set<IJavaClassLoader> getChildren() {
 			return kids;
 		}
 		

Added: incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaClassLoaderImpl.java
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaClassLoaderImpl.java?rev=826984&view=auto
==============================================================================
--- incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaClassLoaderImpl.java
(added)
+++ incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaClassLoaderImpl.java
Tue Oct 20 07:48:11 2009
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+package org.apache.kato.javaview.impl;
+
+import java.util.Set;
+
+import org.apache.kato.javaview.api.IJavaClassLoader;
+
+class JavaClassLoaderImpl implements IJavaClassLoader {
+
+
+	private long id=0;
+	private Datastore store=null;
+	
+	
+	
+	JavaClassLoaderImpl(Datastore store,long id) {
+		this.id=id;
+		this.store=store;
+	
+	}
+	
+	@Override
+	public Set<IJavaClassLoader> getChildren() {
+	
+		return null;
+	}
+
+	@Override
+	public Set<IJavaClassLoader> getParents() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	public long getLoaderID() {
+		return id;
+	}
+
+	
+	
+
+}
\ No newline at end of file

Added: incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaInstanceImpl.java
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaInstanceImpl.java?rev=826984&view=auto
==============================================================================
--- incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaInstanceImpl.java
(added)
+++ incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaInstanceImpl.java
Tue Oct 20 07:48:11 2009
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+package org.apache.kato.javaview.impl;
+
+import javax.tools.diagnostics.runtime.java.JavaField;
+
+import org.apache.kato.javaview.api.IJavaClass;
+import org.apache.kato.javaview.api.IJavaInstance;
+import org.apache.kato.javaview.api.QueryResult;
+
+class JavaInstanceImpl implements IJavaInstance{
+
+	private Datastore store=null;
+	private long id=0;
+	private long clazzid=0;
+	public JavaInstanceImpl(Datastore store,long id, long clazzid) {
+		this.store=store;
+		this.id=id;
+		this.clazzid=clazzid;
+	}
+
+	@Override
+	public QueryResult<JavaField> getFields() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public IJavaClass getJavaClass() {
+		return store.getJavaClass(clazzid);
+	}
+
+	public long getInstanceID() {
+		return id;
+	}
+
+	public long getClassID() {
+
+		return clazzid;
+	}
+	
+}
\ No newline at end of file

Added: incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaViewBuilder.java
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaViewBuilder.java?rev=826984&view=auto
==============================================================================
--- incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaViewBuilder.java
(added)
+++ incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaViewBuilder.java
Tue Oct 20 07:48:11 2009
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+package org.apache.kato.javaview.impl;
+
+import java.io.IOException;
+
+import javax.tools.diagnostics.runtime.java.JavaRuntime;
+
+import org.apache.kato.javaview.api.IJavaView;
+
+
+
+public class JavaViewBuilder {
+
+	
+	public  static IJavaView buildView(JavaRuntime jrt) throws IOException {
+		
+		if(jrt==null) throw new IllegalArgumentException("runtime is null");
+		
+		Datastore s=new SQLDatastore("jdbc:mysql://localhost/javaview");
+		s.open();
+		JavaViewImpl impl=new JavaViewImpl(jrt,s);
+		
+		// add all the class loaders...
+		
+		impl.addClassLoaders();
+		impl.addInstances();
+		
+		s.close();
+		
+		return  impl;
+		
+	}
+
+	
+
+		
+	
+}
+
+

Modified: incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaViewImpl.java
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaViewImpl.java?rev=826984&r1=826983&r2=826984&view=diff
==============================================================================
--- incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaViewImpl.java
(original)
+++ incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/JavaViewImpl.java
Tue Oct 20 07:48:11 2009
@@ -1,42 +1,162 @@
-/*******************************************************************************
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *   http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- ******************************************************************************/
-
-package org.apache.kato.javaview.impl;
-
-import javax.tools.diagnostics.runtime.java.JavaRuntime;
-
-import org.apache.kato.javaview.api.Group;
-import org.apache.kato.javaview.api.JavaInstance;
-import org.apache.kato.javaview.api.JavaView;
-
-public class JavaViewImpl implements JavaView {
-
-	private JavaRuntime runtime=null;
-	private JavaClassLoaderHierarchy loaderHierarchy=null;
-	
-	public JavaViewImpl(JavaRuntime runtime) {
-		if(runtime==null)  throw new IllegalArgumentException("runtime is null");
-		this.runtime=runtime;
-	}
-
-	@Override
-	public Group<JavaInstance> getInstances() {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	
-	
-	
-}
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+package org.apache.kato.javaview.impl;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.runtime.java.JavaClass;
+import javax.tools.diagnostics.runtime.java.JavaClassLoader;
+import javax.tools.diagnostics.runtime.java.JavaHeap;
+import javax.tools.diagnostics.runtime.java.JavaObject;
+import javax.tools.diagnostics.runtime.java.JavaRuntime;
+
+import org.apache.kato.javaview.api.IJavaInstance;
+import org.apache.kato.javaview.api.IJavaView;
+import org.apache.kato.javaview.api.QueryResult;
+import org.apache.kato.javaview.impl.Datastore;
+import org.apache.kato.javaview.impl.JavaClassImpl;
+import org.apache.kato.javaview.impl.JavaClassLoaderImpl;
+import org.apache.kato.javaview.impl.JavaInstanceImpl;
+
+public 
+class JavaViewImpl implements IJavaView {
+
+	Datastore store=null;
+	private JavaRuntime runtime=null;
+	
+	public JavaViewImpl(JavaRuntime jrt, Datastore store) {
+		this.store=store;
+		this.runtime=jrt;
+	}
+	@Override
+	public void close() {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public QueryResult<IJavaInstance> getInstances() throws IOException {
+		// TODO Auto-generated method stub
+		return null;
+	}
+	
+void addInstances() {
+	
+		
+		for(JavaHeap h: runtime.getHeaps()) {
+			for(JavaObject o:h.getObjects()) {
+				try {
+					JavaClass clazz=o.getJavaClass();
+					long clazzid=clazz.getID().getAddress();
+					JavaClassImpl clazzImpl=store.getJavaClass(clazzid);
+					if(clazzImpl==null) {
+						System.out.println("cant find record for "+clazz.getName());
+					}
+					else {
+					long id=o.getID().getAddress();
+					JavaInstanceImpl impl=new JavaInstanceImpl(store,id,clazzid);
+					store.addJavaInstance(impl);
+					
+					
+					}
+					
+				} catch (CorruptDataException e) {
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+				}
+				
+				
+				
+			}
+		}
+		
+	
+		
+	}
+
+	 void addClassLoaders() {
+		
+		
+		
+		int count=0;
+		for(JavaClassLoader jcl:runtime.getJavaClassLoaders()) {
+			
+			
+			long id=1;
+			count++;
+			
+			JavaObject o;
+			try {
+				o = jcl.getObject();
+			
+			if(o!=null) id=o.getID().getAddress();
+			JavaClassLoaderImpl i=new JavaClassLoaderImpl(store,id);
+			store.addJavaClassLoader(i);
+			
+			// add classes...
+			
+			addClasses(store, jcl.getCachedClasses());
+			addClasses(store, jcl.getDefinedClasses());
+			
+			
+			
+			
+			} catch (CorruptDataException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+		}
+		System.out.println("Added "+count+" loaders");
+		
+	}
+
+	 void addClasses(Datastore store, List<JavaClass> list)
+			throws CorruptDataException {
+		for(JavaClass clazz:list) {
+			String name=clazz.getName();
+			long clazzid=clazz.getID().getAddress();
+			long loaderid=1;
+			
+			JavaClassLoader loader=clazz.getClassLoader();
+			if(loader!=null) {
+				JavaObject lobj=loader.getObject();
+				if(lobj!=null) {
+					loaderid=lobj.getID().getAddress();
+				}
+				
+			}
+			
+			clazz.getClassLoader().getObject().getID().getAddress();
+			JavaClassImpl clazzImpl=store.getJavaClass(clazzid);
+			if(clazzImpl==null) {
+				clazzImpl=new JavaClassImpl(store, clazzid,loaderid,name);
+				store.addJavaClass(clazzImpl);
+			}
+			else {
+				String oldName=store.getJavaClass(clazzid).getName();
+				if(oldName.equals(name)==false) {
+					throw new IllegalArgumentException(oldName+" != "+name);
+				}
+			}
+			
+			
+			//clazzImpl.setLoader(impl);
+			//impl.addCachedClass(clazzImpl);
+			
+		}
+	}
+}
\ No newline at end of file

Added: incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/SQLDatastore.java
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/SQLDatastore.java?rev=826984&view=auto
==============================================================================
--- incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/SQLDatastore.java
(added)
+++ incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/impl/SQLDatastore.java
Tue Oct 20 07:48:11 2009
@@ -0,0 +1,175 @@
+package org.apache.kato.javaview.impl;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+public class SQLDatastore implements Datastore{
+
+	Connection connection=null;
+	PreparedStatement insertInstance=null;
+	PreparedStatement getClass=null;
+	PreparedStatement getClassLoader=null;
+	PreparedStatement insertClass=null;
+	PreparedStatement insertClassLoader=null;
+	
+	private String url=null;
+	
+	public SQLDatastore(String url)  {
+		this.url=url;
+		
+	}
+
+	@Override
+	public void addJavaClass(JavaClassImpl clazzImpl) {
+		try {
+			insertClass.setLong(1, clazzImpl.getClassID());
+			insertClass.setLong(2, clazzImpl.getLoaderID());
+			insertClass.setString(3, clazzImpl.getName());
+			insertClass.executeUpdate();
+			
+		} catch (SQLException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		
+		
+	}
+
+	@Override
+	public void addJavaClassLoader(JavaClassLoaderImpl i) {
+		try {
+			insertClassLoader.setLong(1, i.getLoaderID());
+			insertClassLoader.executeUpdate();
+			
+		} catch (SQLException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		
+		
+		
+	}
+
+	@Override
+	public void addJavaInstance(JavaInstanceImpl impl) {
+		try {
+			insertInstance.setLong(1, impl.getInstanceID());
+			insertInstance.setLong(2, impl.getClassID());
+			insertInstance.executeUpdate();
+			
+		} catch (SQLException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		
+		
+	}
+
+	@Override
+	public void close() throws IOException {
+		if(connection==null) throw new IOException("datastore was never opened");
+		try {
+			connection.close();
+		} catch (SQLException e) {
+			throw new IOException(e);
+		}
+		
+		
+	}
+
+	@Override
+	public JavaClassImpl getJavaClass(long clazzid) {
+		
+		try {
+			getClass.setLong(1,clazzid);
+			ResultSet rs=getClass.executeQuery();
+			boolean hasRecord=rs.next();
+			if(hasRecord) {
+				long id=rs.getLong(1);
+				long loader=rs.getLong(2);
+				String name=rs.getString(3);
+				rs.close();
+				return new JavaClassImpl(this, id,loader,name);
+			}
+			else {
+			rs.close();
+			 return null;
+			}
+			
+		} catch (SQLException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		return null;
+	}
+
+	@Override
+	public JavaClassLoaderImpl getJavaClassLoader(long loader) {
+		try {
+			getClassLoader.setLong(1,loader);
+			ResultSet rs=getClass.executeQuery();
+			boolean hasRecord=rs.next();
+			if(hasRecord) {
+				long id=rs.getLong(1);
+				rs.close();
+				return new JavaClassLoaderImpl(this, id);
+			}
+			else {
+			rs.close();
+			 return null;
+			}
+			
+		} catch (SQLException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		return null;
+	}
+
+
+	@Override
+	public void open() throws IOException {
+		if(connection!=null) throw new IOException("datastore is already open");
+		
+		try {
+			connection = DriverManager.getConnection(url,"javaview","javaview");
+			
+			Statement statement=connection.createStatement();
+			
+			// drop tables...
+			try {
+			statement.execute("drop table instances");
+			statement.execute("drop table classes");
+			statement.execute("drop table loaders");
+			} catch(SQLException se) {
+				;
+			}
+			// build tables
+			
+			statement.execute("create table instances ( id bigint PRIMARY KEY, classid bigint )");
+			statement.execute("create table classes   ( id bigint PRIMARY KEY, loaderid bigint, name
varchar(255) )");
+			statement.execute("create table loaders   ( id bigint PRIMARY KEY)");
+			
+			statement.close();
+			
+			// create prepared statements
+			
+			insertInstance    =connection.prepareStatement("insert into instances values(?,?)");
+			insertClass       =connection.prepareStatement("insert into classes values(?,?,?)");
+			insertClassLoader =connection.prepareStatement("insert into loaders values(?)");
+			
+			getClass          =connection.prepareStatement("select * from classes where id=?");
+			getClassLoader    =connection.prepareStatement("select * from loaders where id=?");
+		} catch (SQLException e) {
+			throw new IOException(e);
+		}
+		
+		
+		
+	}
+}



Mime
View raw message