100 private String[][] nullMultiArray;
101
102 private Collection<String> collection;
103 private Map<String, Integer> map;
104 private Map<String, Integer> largeMap;
105
106 private Object[] editableObjectArray;
107 private Collection<Object> editableCollection;
108 private Map<Integer, Object> editableMap;
109
110 private long startTime;
111 private long lastTime;
112 private long updateTime;
113 private long sequenceNumber = 0;
114
115 private boolean stop = false;
116
117 // @jmx.mbean.description("Abstract Webservice deployer")
118 // @javax.management.ManagedAttribute
119 public Testable() {
120 this("Hello there"); //$NON-NLS-1$
121 }
122
123 public Testable(String s) {
124 this(s, 5000);
125 }
126
127 /**
128 * Creates a new Hello bean with given message and update time.
129 *
130 * @param s
131 * a message string
132 * @param updateTime
133 * time between updates of alive time in ms
134 */
135 public Testable(String s, long updateTime) {
136 reinitSimpleData();
137 string = s;
138 lastTime = startTime = System.currentTimeMillis();
139 this.updateTime = updateTime;
140 Thread myTimer = new Thread(this);
151 primitiveCharacter = 'a';
152 character = Character.valueOf('0');
153 nullCharacter = null;
154
155 primitiveByte = Byte.MIN_VALUE;
156 _byte = Byte.valueOf(Byte.MAX_VALUE);
157 nullByte = null;
158
159 primitiveShort = Short.MIN_VALUE;
160 _short = Short.valueOf(Short.MAX_VALUE);
161 nullShort = null;
162
163 primitiveInteger = Integer.MIN_VALUE;
164 integer = Integer.valueOf(Integer.MAX_VALUE);
165 nullInteger = null;
166
167 primitiveLong = Long.MIN_VALUE;
168 _long = Long.valueOf(Long.MAX_VALUE);
169 nullLong = null;
170
171 bigInteger = new BigInteger("123456789012345678901234567890"); //$NON-NLS-1$
172 nullBigInteger = null;
173
174 primitiveFloat = Float.MIN_VALUE;
175 _float = Float.valueOf(Float.MAX_VALUE);
176 nullFloat = null;
177
178 primitiveDouble = Math.E;
179 _double = Double.valueOf(Math.PI);
180 nullDouble = null;
181
182 string = "Hello there"; //$NON-NLS-1$
183 nullString = null;
184
185 primitiveArray = new int[] {1, 2, 3};
186 nullPrimitiveArray = null;
187 primitivBooleanArray = new boolean[] {true, false};
188
189 stringArray = new String[256];
190 for (int i = 0; i < stringArray.length; i += 1) {
191 stringArray[i] = Integer.toHexString(i);
192 }
193 nullStringArray = null;
194
195 multiArray = new String[][] {{"1-1", "1-2", "1-3"}, {"2-2", "2-3"}, {null}, null}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
196 nullMultiArray = null;
197
198 collection = Arrays.asList("one", "two", "three"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
199 map = new Hashtable<>();
200 map.put("one", Integer.valueOf(1)); //$NON-NLS-1$
201 map.put("two", Integer.valueOf(2)); //$NON-NLS-1$
202 map.put("three", Integer.valueOf(3)); //$NON-NLS-1$
203 largeMap = new Hashtable<>();
204 for (int i = 0; i < 256; i += 1) {
205 largeMap.put("nr_" + i, Integer.valueOf(i)); //$NON-NLS-1$
206 }
207
208 editableObjectArray = new Object[] {1, Float.valueOf(1.5f), "two", null}; //$NON-NLS-1$
209 editableCollection = new ArrayList<>();
210 editableCollection.add(1);
211 editableCollection.add(Float.valueOf(1.5f));
212 editableCollection.add("two"); //$NON-NLS-1$
213 editableMap = new Hashtable<>();
214 editableMap.put(0, 1);
215 editableMap.put(1, Float.valueOf(1.5f));
216 editableMap.put(2, "two"); //$NON-NLS-1$
217 }
218
219 // Boolean
220 @Override
221 public boolean getPrimitiveBoolean() {
222 return primitiveBoolean;
223 }
224
225 @Override
226 public void setPrimitiveBoolean(boolean b) {
227 primitiveBoolean = b;
228 }
229
230 @Override
231 public boolean getReadOnlyPrimitiveBoolean() {
232 return primitiveBoolean;
233 }
234
235 @Override
236 public Boolean getBoolean() {
706
707 // Collection
708 @Override
709 public Collection<String> getCollection() {
710 return collection;
711 }
712
713 @Override
714 public void setCollection(Collection<String> collection) {
715 this.collection = collection;
716 }
717
718 @Override
719 public Collection<String> getReadOnlyCollection() {
720 return collection;
721 }
722
723 @Override
724 public Collection<Object> getReadOnlyObjectCollection() {
725 Collection<Object> c = new ArrayList<>();
726 c.add("one"); //$NON-NLS-1$
727 c.add("two"); //$NON-NLS-1$
728 c.add("three"); //$NON-NLS-1$
729 return c;
730 }
731
732 @Override
733 public Collection<Object> getReadOnlyNullCollection() {
734 return null;
735 }
736
737 public Collection<String> theReadOnlyCollection() {
738 return getReadOnlyCollection();
739 }
740
741 // Map
742 @Override
743 public Map<String, Integer> getMap() {
744 return map;
745 }
746
747 @Override
748 public void setMap(Map<String, Integer> map) {
755 }
756
757 @Override
758 public Map<String, Integer> getReadOnlyLargeMap() {
759 return largeMap;
760 }
761
762 @Override
763 public Map<Object, Object> getReadOnlyNullMap() {
764 return null;
765 }
766
767 /****/
768
769 /*
770 * public Class<? extends TestMBean> getUneditableClass() { return getClass(); }
771 */
772
773 @Override
774 public TestContainer getUneditableTestContainer() {
775 return new TestContainer(new String[] {"this", "is", "an", "opaque", "object"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
776 }
777
778 @Override
779 public TestableMBean[] getUneditableArray() {
780 return new TestableMBean[] {this};
781 }
782
783 @Override
784 public Object[] getUneditableObjectArray() {
785 return getUneditableArray();
786 }
787
788 @Override
789 public Object[] getAnotherUneditableObjectArray() {
790 return new Object[] {this};
791 }
792
793 @Override
794 public Object[] getEditableObjectArray() {
795 return editableObjectArray;
810 this.editableCollection = editableCollection;
811 }
812
813 @Override
814 public Map<Integer, Object> getEditableMap() {
815 return editableMap;
816 }
817
818 @Override
819 public void setEditableMap(Map<Integer, Object> editableMap) {
820 this.editableMap = editableMap;
821 }
822
823 @Override
824 public void run() {
825 while (!stop) {
826 synchronized (this) {
827 long oldLastTime = lastTime;
828 lastTime = System.currentTimeMillis();
829 // System.out.println("Current time: " + getAliveTime());
830 sendNotification(new AttributeChangeNotification(this, sequenceNumber++, lastTime, "Update", //$NON-NLS-1$
831 "AliveTime", "long", Long.valueOf(oldLastTime - startTime), //$NON-NLS-1$ //$NON-NLS-2$
832 Long.valueOf(lastTime - startTime))); //$NON-NLS-1$ //$NON-NLS-2$
833 try {
834 wait(Math.max(1, updateTime));
835 } catch (InterruptedException e) {
836 }
837 }
838 }
839 }
840
841 @Override
842 public long getAliveTime() {
843 return lastTime - startTime;
844 }
845
846 @Override
847 public void resetAliveTime() {
848 synchronized (this) {
849 lastTime = startTime = System.currentTimeMillis();
850 notify();
851 }
852 }
853
854 @Override
855 public long getUpdateTime() {
856 return updateTime;
857 }
858
859 @Override
860 public void setUpdateTime(long updateTime) {
861 synchronized (this) {
862 this.updateTime = updateTime;
863 notify();
864 }
865 }
866
867 @Override
868 public boolean killExistingHelloMBean(String name) {
869 try {
870 ObjectName mbeanName = new ObjectName("SimpleAgent:name=" + name); //$NON-NLS-1$
871 ManagementFactory.getPlatformMBeanServer().unregisterMBean(mbeanName);
872 return true;
873 } catch (Exception e) {
874 e.printStackTrace();
875 return false;
876 }
877 }
878
879 @Override
880 public boolean startNewHelloMBeanWithType(String name, String type) {
881 Testable test = new Testable();
882 ObjectName mbeanName = null;
883
884 try {
885 mbeanName = new ObjectName("SimpleAgent:name=" + name + ',' + type); //$NON-NLS-1$
886 ManagementFactory.getPlatformMBeanServer().registerMBean(test, mbeanName);
887 return true;
888 } catch (Exception e) {
889 e.printStackTrace();
890 test.stop = true;
891 return false;
892 }
893 }
894
895 @Override
896 public boolean startNewHelloMBean(String name) {
897 return startNewHelloMBeanWithType(name, "type=added"); //$NON-NLS-1$
898 }
899
900 @Override
901 public boolean startManyNewHelloMBean(String name, int number) {
902 for (int i = 0; i < number; i += 1) {
903 if (!startNewHelloMBean(name + '_' + i)) {
904 return false;
905 }
906 }
907 return true;
908 }
909
910 @Override
911 public void gc() {
912 System.gc();
913 }
914
915 @Override
916 public MBeanNotificationInfo[] getNotificationInfo() {
917 String[] types = new String[] {AttributeChangeNotification.ATTRIBUTE_CHANGE};
918 String name = AttributeChangeNotification.class.getName();
919 String description = "An attribute of this MBean has changed"; //$NON-NLS-1$
920 MBeanNotificationInfo info = new MBeanNotificationInfo(types, name, description);
921 return new MBeanNotificationInfo[] {info};
922 }
923 }
|
100 private String[][] nullMultiArray;
101
102 private Collection<String> collection;
103 private Map<String, Integer> map;
104 private Map<String, Integer> largeMap;
105
106 private Object[] editableObjectArray;
107 private Collection<Object> editableCollection;
108 private Map<Integer, Object> editableMap;
109
110 private long startTime;
111 private long lastTime;
112 private long updateTime;
113 private long sequenceNumber = 0;
114
115 private boolean stop = false;
116
117 // @jmx.mbean.description("Abstract Webservice deployer")
118 // @javax.management.ManagedAttribute
119 public Testable() {
120 this("Hello there");
121 }
122
123 public Testable(String s) {
124 this(s, 5000);
125 }
126
127 /**
128 * Creates a new Hello bean with given message and update time.
129 *
130 * @param s
131 * a message string
132 * @param updateTime
133 * time between updates of alive time in ms
134 */
135 public Testable(String s, long updateTime) {
136 reinitSimpleData();
137 string = s;
138 lastTime = startTime = System.currentTimeMillis();
139 this.updateTime = updateTime;
140 Thread myTimer = new Thread(this);
151 primitiveCharacter = 'a';
152 character = Character.valueOf('0');
153 nullCharacter = null;
154
155 primitiveByte = Byte.MIN_VALUE;
156 _byte = Byte.valueOf(Byte.MAX_VALUE);
157 nullByte = null;
158
159 primitiveShort = Short.MIN_VALUE;
160 _short = Short.valueOf(Short.MAX_VALUE);
161 nullShort = null;
162
163 primitiveInteger = Integer.MIN_VALUE;
164 integer = Integer.valueOf(Integer.MAX_VALUE);
165 nullInteger = null;
166
167 primitiveLong = Long.MIN_VALUE;
168 _long = Long.valueOf(Long.MAX_VALUE);
169 nullLong = null;
170
171 bigInteger = new BigInteger("123456789012345678901234567890");
172 nullBigInteger = null;
173
174 primitiveFloat = Float.MIN_VALUE;
175 _float = Float.valueOf(Float.MAX_VALUE);
176 nullFloat = null;
177
178 primitiveDouble = Math.E;
179 _double = Double.valueOf(Math.PI);
180 nullDouble = null;
181
182 string = "Hello there";
183 nullString = null;
184
185 primitiveArray = new int[] {1, 2, 3};
186 nullPrimitiveArray = null;
187 primitivBooleanArray = new boolean[] {true, false};
188
189 stringArray = new String[256];
190 for (int i = 0; i < stringArray.length; i += 1) {
191 stringArray[i] = Integer.toHexString(i);
192 }
193 nullStringArray = null;
194
195 multiArray = new String[][] {{"1-1", "1-2", "1-3"}, {"2-2", "2-3"}, {null}, null};
196 nullMultiArray = null;
197
198 collection = Arrays.asList("one", "two", "three");
199 map = new Hashtable<>();
200 map.put("one", Integer.valueOf(1));
201 map.put("two", Integer.valueOf(2));
202 map.put("three", Integer.valueOf(3));
203 largeMap = new Hashtable<>();
204 for (int i = 0; i < 256; i += 1) {
205 largeMap.put("nr_" + i, Integer.valueOf(i));
206 }
207
208 editableObjectArray = new Object[] {1, Float.valueOf(1.5f), "two", null};
209 editableCollection = new ArrayList<>();
210 editableCollection.add(1);
211 editableCollection.add(Float.valueOf(1.5f));
212 editableCollection.add("two");
213 editableMap = new Hashtable<>();
214 editableMap.put(0, 1);
215 editableMap.put(1, Float.valueOf(1.5f));
216 editableMap.put(2, "two");
217 }
218
219 // Boolean
220 @Override
221 public boolean getPrimitiveBoolean() {
222 return primitiveBoolean;
223 }
224
225 @Override
226 public void setPrimitiveBoolean(boolean b) {
227 primitiveBoolean = b;
228 }
229
230 @Override
231 public boolean getReadOnlyPrimitiveBoolean() {
232 return primitiveBoolean;
233 }
234
235 @Override
236 public Boolean getBoolean() {
706
707 // Collection
708 @Override
709 public Collection<String> getCollection() {
710 return collection;
711 }
712
713 @Override
714 public void setCollection(Collection<String> collection) {
715 this.collection = collection;
716 }
717
718 @Override
719 public Collection<String> getReadOnlyCollection() {
720 return collection;
721 }
722
723 @Override
724 public Collection<Object> getReadOnlyObjectCollection() {
725 Collection<Object> c = new ArrayList<>();
726 c.add("one");
727 c.add("two");
728 c.add("three");
729 return c;
730 }
731
732 @Override
733 public Collection<Object> getReadOnlyNullCollection() {
734 return null;
735 }
736
737 public Collection<String> theReadOnlyCollection() {
738 return getReadOnlyCollection();
739 }
740
741 // Map
742 @Override
743 public Map<String, Integer> getMap() {
744 return map;
745 }
746
747 @Override
748 public void setMap(Map<String, Integer> map) {
755 }
756
757 @Override
758 public Map<String, Integer> getReadOnlyLargeMap() {
759 return largeMap;
760 }
761
762 @Override
763 public Map<Object, Object> getReadOnlyNullMap() {
764 return null;
765 }
766
767 /****/
768
769 /*
770 * public Class<? extends TestMBean> getUneditableClass() { return getClass(); }
771 */
772
773 @Override
774 public TestContainer getUneditableTestContainer() {
775 return new TestContainer(new String[] {"this", "is", "an", "opaque", "object"});
776 }
777
778 @Override
779 public TestableMBean[] getUneditableArray() {
780 return new TestableMBean[] {this};
781 }
782
783 @Override
784 public Object[] getUneditableObjectArray() {
785 return getUneditableArray();
786 }
787
788 @Override
789 public Object[] getAnotherUneditableObjectArray() {
790 return new Object[] {this};
791 }
792
793 @Override
794 public Object[] getEditableObjectArray() {
795 return editableObjectArray;
810 this.editableCollection = editableCollection;
811 }
812
813 @Override
814 public Map<Integer, Object> getEditableMap() {
815 return editableMap;
816 }
817
818 @Override
819 public void setEditableMap(Map<Integer, Object> editableMap) {
820 this.editableMap = editableMap;
821 }
822
823 @Override
824 public void run() {
825 while (!stop) {
826 synchronized (this) {
827 long oldLastTime = lastTime;
828 lastTime = System.currentTimeMillis();
829 // System.out.println("Current time: " + getAliveTime());
830 sendNotification(new AttributeChangeNotification(this, sequenceNumber++, lastTime, "Update",
831 "AliveTime", "long", Long.valueOf(oldLastTime - startTime),
832 Long.valueOf(lastTime - startTime)));
833 try {
834 wait(Math.max(1, updateTime));
835 } catch (InterruptedException e) {
836 }
837 }
838 }
839 }
840
841 @Override
842 public long getAliveTime() {
843 return lastTime - startTime;
844 }
845
846 @Override
847 public void resetAliveTime() {
848 synchronized (this) {
849 lastTime = startTime = System.currentTimeMillis();
850 notify();
851 }
852 }
853
854 @Override
855 public long getUpdateTime() {
856 return updateTime;
857 }
858
859 @Override
860 public void setUpdateTime(long updateTime) {
861 synchronized (this) {
862 this.updateTime = updateTime;
863 notify();
864 }
865 }
866
867 @Override
868 public boolean killExistingHelloMBean(String name) {
869 try {
870 ObjectName mbeanName = new ObjectName("SimpleAgent:name=" + name);
871 ManagementFactory.getPlatformMBeanServer().unregisterMBean(mbeanName);
872 return true;
873 } catch (Exception e) {
874 e.printStackTrace();
875 return false;
876 }
877 }
878
879 @Override
880 public boolean startNewHelloMBeanWithType(String name, String type) {
881 Testable test = new Testable();
882 ObjectName mbeanName = null;
883
884 try {
885 mbeanName = new ObjectName("SimpleAgent:name=" + name + ',' + type);
886 ManagementFactory.getPlatformMBeanServer().registerMBean(test, mbeanName);
887 return true;
888 } catch (Exception e) {
889 e.printStackTrace();
890 test.stop = true;
891 return false;
892 }
893 }
894
895 @Override
896 public boolean startNewHelloMBean(String name) {
897 return startNewHelloMBeanWithType(name, "type=added");
898 }
899
900 @Override
901 public boolean startManyNewHelloMBean(String name, int number) {
902 for (int i = 0; i < number; i += 1) {
903 if (!startNewHelloMBean(name + '_' + i)) {
904 return false;
905 }
906 }
907 return true;
908 }
909
910 @Override
911 public void gc() {
912 System.gc();
913 }
914
915 @Override
916 public MBeanNotificationInfo[] getNotificationInfo() {
917 String[] types = new String[] {AttributeChangeNotification.ATTRIBUTE_CHANGE};
918 String name = AttributeChangeNotification.class.getName();
919 String description = "An attribute of this MBean has changed";
920 MBeanNotificationInfo info = new MBeanNotificationInfo(types, name, description);
921 return new MBeanNotificationInfo[] {info};
922 }
923 }
|