[Design of Clustering on JBoss (Clusters/JBoss)] - Re: JBAS-3532 Design
by JerryGauth
Brian - I'm documenting my progress here as I'll be away on vacation when you return.
The required dependencies are as follows. The dependency states are reversed from your example.
| <bean name="DistributedReplicantManager" ...
| <property name="HAPartition"><inject bean="HAPartition" state="Create"/></property>
| <depends>HAPartition</depends>
| </bean>
|
| <bean name="HAPartition" ...
| <property name="distributedReplicantManager"><inject bean="DistributedReplicantManager" state="Instantiated"/></property>
| </bean>
|
I've checked in the changes necessary to provide dependency injection and I've removed the logic that supported usage of ClusterPartition without DI of DRM (as it appears that was your intent).
This implementation differs from DI of DistributedState where DS was injected into ClusterPartitionConfig which was then passed into the ClusterPartition constructor. My implementation injects DRM directly into ClusterPartition as I couldn't resolve the circular dependencies between DRM and ClusterPartition when injecting into the Config object. I'm going to revisit this as I may have missed something when trying it earlier.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4072215#4072215
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4072215
18 years, 8 months
[Design the new POJO MicroContainer] - Re: ClassCastException for char[] MetaValue creation
by scott.stark@jboss.org
"alesj" wrote : "scott.stark(a)jboss.org" wrote :
| | I also ran across JBMICROCONT-123 which is about improving the implementation, but this is actually a bug as this method does not work at all. The depth argument to Array.newInstance is the array length, not a depth for the array dimension.
| |
| | | public static Class getArrayClass(Class clazz, int depth)
| | | {
| | | return Array.newInstance(clazz, depth).getClass();
| | | }
| | |
| |
|
| What's the deal with this one then?
| I saw you did an assignment ping-pong. :-)
| Do you need it fixed right away?
| How come we didn't see this (The depth argument to Array.newInstance is the array length, not a depth for the array dimension.) before? ;-)
The question is what the getArrayClass(Class, int) method is supposed to do. If its supposed to create a Class[] from Class, then the depth argument is irrelevant, and misleading. There is no such type as Class[int length].
If its supposed to create a depth dimensional array of Class, then its broken. Based on the existing tests, it seems to be the former and it should just be:
| public static Class getArrayClass(Class clazz)
| {
| return Array.newInstance(clazz, 0).getClass();
| }
|
In terms of JBMICROCONT-123, I don't think there is a better way to do this as I see the same logic in the jdk code. So either the blind are leading the blind and that is where we got this construct from, or there is no other way to create an array Class.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4072112#4072112
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4072112
18 years, 8 months
[Design the new POJO MicroContainer] - Re: ClassCastException for char[] MetaValue creation
by scott.stark@jboss.org
I have the following changes to the ArrayValue interface working and can preserve the primitive type arrays:
| public interface ArrayValue<T extends Serializable>
| extends MetaValue, Iterable<T>
| {
| ArrayMetaType<T> getMetaType();
|
| /**
| * Get the underlying array value. This will not be an
| * Object[] in general.
| * @see #getValue(int)
| *
| * @return the underlying value
| */
| public Object getValue();
| /**
| * Get the length of the array.
| * @return length of the array.
| */
| public int getLength();
| /**
| * Get the array element at index.
| * @param index - index into the array.
| * @return element at index.
| */
| public Object getValue(int index);
| }
|
As this ArrayValueSupportUnitTestCase test shows, you can use the getValue(int) accessor, the type safe foreach Iterable, or the raw array:
| public void testCharArray() throws Exception
| {
| ArrayMetaType<Character> type = new ArrayMetaType<Character>(1, SimpleMetaType.CHARACTER);
| char[] value = {'h', 'e', 'l', 'l', 'o'};
| ArrayValueSupport<Character> avs = new ArrayValueSupport<Character>(type, value);
| // Use getValue(int) accessor
| for(int n = 0; n < avs.getLength(); n ++)
| {
| Object element = avs.getValue(n);
| assertEquals(value[n], element);
| }
| // Use typesafe foreach Iterable
| int i = 0;
| for(Character c : avs)
| {
| assertEquals("["+i+"]", (Character) value[i++], c);
| }
| // Validate the primative array
| char[] raw = (char[]) avs.getValue();
| for(int n = 0; n < value.length; n ++)
| {
| assertEquals(value[n], raw[n]);
| }
| }
|
There are quirks for multi-dimensional primitive arrays though. This 2d char[][] test shows them:
| public void test2DCharArray() throws Exception
| {
| ArrayMetaType<Character[]> type = new ArrayMetaType<Character[]>(2, SimpleMetaType.CHARACTER, true);
| char[][] value = {{'h', 'e'}, {'l', 'l', 'o'}};
| ArrayValueSupport<Character[]> avs = new ArrayValueSupport<Character[]>(type, value);
| assertEquals(value.length, avs.getLength());
| for(int m = 0; m < value.length; m ++)
| {
| Object arraym = avs.getValue(m);
| for(int n = 0; n < value[m].length; n ++)
| {
| // Have to use the java.lang.reflect.Array to access nested elements
| Object valuenm = Array.get(arraym, n);
| assertEquals("["+m+"]["+n+"]", value[m][n], valuenm);
| }
| }
| // Use typesafe foreach Iterable: current broken with CCE on [C
| int i = 0, j = 0;
| for(Character[] carray : avs) // CCE here
| {
| for(Character c : carray)
| {
| Character cij = value[i ++][j ++];
| assertEquals("["+i+"], ["+j+"]", cij , c);
| }
| }
| // Validate the primitive 2d array
| char[][] raw = (char[][]) avs.getValue();
| for(int m = 0; m < value.length; m ++)
| {
| for(int n = 0; n < value[m].length; n ++)
| {
| assertEquals("["+m+"]["+n+"]", value[m][n], raw[m][n]);
| }
| }
| }
|
The first is that you have to use java.lang.reflect.Array.get(Object, int) to access the elements of the nested arrays obtained via the get(int) accessor.
The second is that the Iterable implementation on ArrayValueSupport needs to track whether the underlying value is a primitive array, and covert it to the primitive wrapper form to avoid the CCE.
Before going further I want to see if we agree that this is the way to go.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4072109#4072109
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4072109
18 years, 8 months