From cd15d32a74b0ad4ea281090b67537bd437c98c08 Mon Sep 17 00:00:00 2001
From: Stuart Marks
*
* This interface is a member of the
- *
+ *
* Java Collections Framework.
*
* @param
*
* This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @author Josh Bloch
diff --git a/jdk/src/java.base/share/classes/java/util/AbstractCollection.java b/jdk/src/java.base/share/classes/java/util/AbstractCollection.java
index 6f344f8befe..9845c0f031b 100644
--- a/jdk/src/java.base/share/classes/java/util/AbstractCollection.java
+++ b/jdk/src/java.base/share/classes/java/util/AbstractCollection.java
@@ -49,7 +49,7 @@ package java.util;
* the collection being implemented admits a more efficient implementation.
*
* This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @author Josh Bloch
diff --git a/jdk/src/java.base/share/classes/java/util/AbstractList.java b/jdk/src/java.base/share/classes/java/util/AbstractList.java
index c8c160de6a4..6d819368a24 100644
--- a/jdk/src/java.base/share/classes/java/util/AbstractList.java
+++ b/jdk/src/java.base/share/classes/java/util/AbstractList.java
@@ -62,7 +62,7 @@ import java.util.function.Consumer;
* collection being implemented admits a more efficient implementation.
*
* This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @author Josh Bloch
diff --git a/jdk/src/java.base/share/classes/java/util/AbstractMap.java b/jdk/src/java.base/share/classes/java/util/AbstractMap.java
index 0b76ddd76b1..ed39bcacbca 100644
--- a/jdk/src/java.base/share/classes/java/util/AbstractMap.java
+++ b/jdk/src/java.base/share/classes/java/util/AbstractMap.java
@@ -52,7 +52,7 @@ import java.util.Map.Entry;
* map being implemented admits a more efficient implementation.
*
* This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @param This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @since 1.5
diff --git a/jdk/src/java.base/share/classes/java/util/AbstractSequentialList.java b/jdk/src/java.base/share/classes/java/util/AbstractSequentialList.java
index bd6736ba63c..0e7cb01938a 100644
--- a/jdk/src/java.base/share/classes/java/util/AbstractSequentialList.java
+++ b/jdk/src/java.base/share/classes/java/util/AbstractSequentialList.java
@@ -54,7 +54,7 @@ package java.util;
* specification.
*
* This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @author Josh Bloch
diff --git a/jdk/src/java.base/share/classes/java/util/AbstractSet.java b/jdk/src/java.base/share/classes/java/util/AbstractSet.java
index 35e2ba4ec99..534ef775db1 100644
--- a/jdk/src/java.base/share/classes/java/util/AbstractSet.java
+++ b/jdk/src/java.base/share/classes/java/util/AbstractSet.java
@@ -42,7 +42,7 @@ package java.util;
* for {@code equals} and {@code hashCode}.
*
* This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @param This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @author Josh Bloch and Doug Lea
diff --git a/jdk/src/java.base/share/classes/java/util/ArrayList.java b/jdk/src/java.base/share/classes/java/util/ArrayList.java
index dbaa725dacb..f63ef493dc0 100644
--- a/jdk/src/java.base/share/classes/java/util/ArrayList.java
+++ b/jdk/src/java.base/share/classes/java/util/ArrayList.java
@@ -91,7 +91,7 @@ import java.util.function.UnaryOperator;
* should be used only to detect bugs.
*
* This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @param This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @author Josh Bloch
@@ -8899,4 +8899,4 @@ public class Arrays {
return aLength != bLength ? length : -1;
}
-}
\ No newline at end of file
+}
diff --git a/jdk/src/java.base/share/classes/java/util/Collection.java b/jdk/src/java.base/share/classes/java/util/Collection.java
index f92b9f6153f..a1fc025c89f 100644
--- a/jdk/src/java.base/share/classes/java/util/Collection.java
+++ b/jdk/src/java.base/share/classes/java/util/Collection.java
@@ -112,7 +112,7 @@ import java.util.stream.StreamSupport;
* however most current implementations do not do so.
*
* This interface is a member of the
- *
+ *
* Java Collections Framework.
*
* @implSpec
diff --git a/jdk/src/java.base/share/classes/java/util/Collections.java b/jdk/src/java.base/share/classes/java/util/Collections.java
index 22b4557ae2f..8aa9c53c455 100644
--- a/jdk/src/java.base/share/classes/java/util/Collections.java
+++ b/jdk/src/java.base/share/classes/java/util/Collections.java
@@ -65,7 +65,7 @@ import java.util.stream.StreamSupport;
* already sorted may or may not throw {@code UnsupportedOperationException}.
*
* This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @author Josh Bloch
diff --git a/jdk/src/java.base/share/classes/java/util/Comparator.java b/jdk/src/java.base/share/classes/java/util/Comparator.java
index 85f25beaf63..1e95e6279bb 100644
--- a/jdk/src/java.base/share/classes/java/util/Comparator.java
+++ b/jdk/src/java.base/share/classes/java/util/Comparator.java
@@ -94,7 +94,7 @@ import java.util.Comparators;
* an equivalence relation.
*
* This interface is a member of the
- *
+ *
* Java Collections Framework.
*
* @param This interface is a member of the Java Collections
- * Framework.
+ * This interface is a member of the
+ *
+ * Java Collections Framework.
*
* @author Doug Lea
* @author Josh Bloch
diff --git a/jdk/src/java.base/share/classes/java/util/EnumMap.java b/jdk/src/java.base/share/classes/java/util/EnumMap.java
index e6d63cf4ae8..3eff9a6fd3a 100644
--- a/jdk/src/java.base/share/classes/java/util/EnumMap.java
+++ b/jdk/src/java.base/share/classes/java/util/EnumMap.java
@@ -68,7 +68,7 @@ import jdk.internal.misc.SharedSecrets;
* {@link HashMap} counterparts.
*
* This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @author Josh Bloch
diff --git a/jdk/src/java.base/share/classes/java/util/EnumSet.java b/jdk/src/java.base/share/classes/java/util/EnumSet.java
index 0ca61870976..0adeab410b0 100644
--- a/jdk/src/java.base/share/classes/java/util/EnumSet.java
+++ b/jdk/src/java.base/share/classes/java/util/EnumSet.java
@@ -69,7 +69,7 @@ import jdk.internal.misc.SharedSecrets;
* constant time if their argument is also an enum set.
*
* This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @author Josh Bloch
diff --git a/jdk/src/java.base/share/classes/java/util/HashMap.java b/jdk/src/java.base/share/classes/java/util/HashMap.java
index 5cc36296aa8..4f0e8e6c7d6 100644
--- a/jdk/src/java.base/share/classes/java/util/HashMap.java
+++ b/jdk/src/java.base/share/classes/java/util/HashMap.java
@@ -117,7 +117,7 @@ import java.util.function.Function;
* should be used only to detect bugs.
*
* This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @param This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @param As of the Java 2 platform v1.2, this class was retrofitted to
* implement the {@link Map} interface, making it a member of the
- *
+ *
*
* Java Collections Framework. Unlike the new collection
* implementations, {@code Hashtable} is synchronized. If a
diff --git a/jdk/src/java.base/share/classes/java/util/IdentityHashMap.java b/jdk/src/java.base/share/classes/java/util/IdentityHashMap.java
index bd1e217e7ff..f749774e78e 100644
--- a/jdk/src/java.base/share/classes/java/util/IdentityHashMap.java
+++ b/jdk/src/java.base/share/classes/java/util/IdentityHashMap.java
@@ -122,7 +122,7 @@ import java.util.function.Consumer;
* {@link HashMap} (which uses chaining rather than linear-probing).
*
* This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @see System#identityHashCode(Object)
diff --git a/jdk/src/java.base/share/classes/java/util/Iterator.java b/jdk/src/java.base/share/classes/java/util/Iterator.java
index a5d89293a2c..5f7b1de8b85 100644
--- a/jdk/src/java.base/share/classes/java/util/Iterator.java
+++ b/jdk/src/java.base/share/classes/java/util/Iterator.java
@@ -40,7 +40,7 @@ import java.util.function.Consumer;
*
*
* This interface is a member of the
- *
+ *
* Java Collections Framework.
*
* @apiNote
diff --git a/jdk/src/java.base/share/classes/java/util/LinkedHashMap.java b/jdk/src/java.base/share/classes/java/util/LinkedHashMap.java
index bd21f5bf6d4..252a5437353 100644
--- a/jdk/src/java.base/share/classes/java/util/LinkedHashMap.java
+++ b/jdk/src/java.base/share/classes/java/util/LinkedHashMap.java
@@ -140,7 +140,7 @@ import java.io.IOException;
* fail-fast, and additionally report {@link Spliterator#ORDERED}.
*
* This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @implNote
diff --git a/jdk/src/java.base/share/classes/java/util/LinkedHashSet.java b/jdk/src/java.base/share/classes/java/util/LinkedHashSet.java
index c0e1f2eb8e4..0d0f927166e 100644
--- a/jdk/src/java.base/share/classes/java/util/LinkedHashSet.java
+++ b/jdk/src/java.base/share/classes/java/util/LinkedHashSet.java
@@ -100,7 +100,7 @@ package java.util;
* should be used only to detect bugs.
*
* This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @param This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @author Josh Bloch
diff --git a/jdk/src/java.base/share/classes/java/util/List.java b/jdk/src/java.base/share/classes/java/util/List.java
index dda514b313f..c0a9b31ba2f 100644
--- a/jdk/src/java.base/share/classes/java/util/List.java
+++ b/jdk/src/java.base/share/classes/java/util/List.java
@@ -114,7 +114,7 @@ import java.util.function.UnaryOperator;
*
*
* This interface is a member of the
- *
+ *
* Java Collections Framework.
*
* @param This interface is a member of the
- *
+ *
* Java Collections Framework.
*
* @author Josh Bloch
diff --git a/jdk/src/java.base/share/classes/java/util/Map.java b/jdk/src/java.base/share/classes/java/util/Map.java
index 153b86b8084..9b03346a72e 100644
--- a/jdk/src/java.base/share/classes/java/util/Map.java
+++ b/jdk/src/java.base/share/classes/java/util/Map.java
@@ -140,7 +140,7 @@ import java.io.Serializable;
*
*
* This interface is a member of the
- *
+ *
* Java Collections Framework.
*
* @param This interface is a member of the
- *
+ *
* Java Collections Framework.
*
* @author Doug Lea
diff --git a/jdk/src/java.base/share/classes/java/util/NavigableSet.java b/jdk/src/java.base/share/classes/java/util/NavigableSet.java
index 40843905271..4f1f0d510a9 100644
--- a/jdk/src/java.base/share/classes/java/util/NavigableSet.java
+++ b/jdk/src/java.base/share/classes/java/util/NavigableSet.java
@@ -79,7 +79,7 @@ package java.util;
* {@code NavigableSet}.
*
* This interface is a member of the
- *
+ *
* Java Collections Framework.
*
* @author Doug Lea
diff --git a/jdk/src/java.base/share/classes/java/util/PriorityQueue.java b/jdk/src/java.base/share/classes/java/util/PriorityQueue.java
index 829eb01efea..28111ae16bf 100644
--- a/jdk/src/java.base/share/classes/java/util/PriorityQueue.java
+++ b/jdk/src/java.base/share/classes/java/util/PriorityQueue.java
@@ -73,7 +73,7 @@ import java.util.function.Consumer;
* ({@code peek}, {@code element}, and {@code size}).
*
* This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @since 1.5
diff --git a/jdk/src/java.base/share/classes/java/util/Queue.java b/jdk/src/java.base/share/classes/java/util/Queue.java
index e94b22c7fb2..1a46d9e723c 100644
--- a/jdk/src/java.base/share/classes/java/util/Queue.java
+++ b/jdk/src/java.base/share/classes/java/util/Queue.java
@@ -125,7 +125,7 @@ package java.util;
* ordering properties.
*
* This interface is a member of the
- *
+ *
* Java Collections Framework.
*
* @since 1.5
diff --git a/jdk/src/java.base/share/classes/java/util/RandomAccess.java b/jdk/src/java.base/share/classes/java/util/RandomAccess.java
index a4d489313de..09793e633f6 100644
--- a/jdk/src/java.base/share/classes/java/util/RandomAccess.java
+++ b/jdk/src/java.base/share/classes/java/util/RandomAccess.java
@@ -59,7 +59,7 @@ package java.util;
*
*
* This interface is a member of the
- *
+ *
* Java Collections Framework.
*
* @since 1.4
diff --git a/jdk/src/java.base/share/classes/java/util/Set.java b/jdk/src/java.base/share/classes/java/util/Set.java
index 2dd9060f7df..38be624cbef 100644
--- a/jdk/src/java.base/share/classes/java/util/Set.java
+++ b/jdk/src/java.base/share/classes/java/util/Set.java
@@ -91,7 +91,7 @@ package java.util;
*
*
* This interface is a member of the
- *
+ *
* Java Collections Framework.
*
* @param This interface is a member of the
- *
+ *
* Java Collections Framework.
*
* @param This interface is a member of the
- *
+ *
* Java Collections Framework.
*
* @param This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @param This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @param As of the Java 2 platform v1.2, this class was retrofitted to
* implement the {@link List} interface, making it a member of the
- *
+ *
* Java Collections Framework. Unlike the new collection
* implementations, {@code Vector} is synchronized. If a thread-safe
* implementation is not needed, it is recommended to use {@link
diff --git a/jdk/src/java.base/share/classes/java/util/WeakHashMap.java b/jdk/src/java.base/share/classes/java/util/WeakHashMap.java
index 1aa8ec4396d..183b4c39729 100644
--- a/jdk/src/java.base/share/classes/java/util/WeakHashMap.java
+++ b/jdk/src/java.base/share/classes/java/util/WeakHashMap.java
@@ -120,7 +120,7 @@ import java.util.function.Consumer;
* should be used only to detect bugs.
*
* This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @param This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @since 1.5
diff --git a/jdk/src/java.base/share/classes/java/util/concurrent/BlockingDeque.java b/jdk/src/java.base/share/classes/java/util/concurrent/BlockingDeque.java
index 27b05bf711b..12b088bb6f7 100644
--- a/jdk/src/java.base/share/classes/java/util/concurrent/BlockingDeque.java
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/BlockingDeque.java
@@ -193,7 +193,7 @@ import java.util.NoSuchElementException;
* the {@code BlockingDeque} in another thread.
*
* This interface is a member of the
- *
+ *
* Java Collections Framework.
*
* @since 1.6
diff --git a/jdk/src/java.base/share/classes/java/util/concurrent/BlockingQueue.java b/jdk/src/java.base/share/classes/java/util/concurrent/BlockingQueue.java
index 03ca56d8791..7bae2ba0437 100644
--- a/jdk/src/java.base/share/classes/java/util/concurrent/BlockingQueue.java
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/BlockingQueue.java
@@ -170,7 +170,7 @@ import java.util.Queue;
* the {@code BlockingQueue} in another thread.
*
* This interface is a member of the
- *
+ *
* Java Collections Framework.
*
* @since 1.5
diff --git a/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java b/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java
index 1d80077b58c..77c42efd6fd 100644
--- a/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java
@@ -254,7 +254,7 @@ import jdk.internal.misc.Unsafe;
* All arguments to all task methods must be non-null.
*
* This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @since 1.5
diff --git a/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java b/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java
index 58e16ae83b8..8546bfb3f46 100644
--- a/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java
@@ -85,7 +85,7 @@ import java.util.function.Predicate;
* the {@code ConcurrentLinkedDeque} in another thread.
*
* This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @since 1.7
diff --git a/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java b/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java
index 6ce61b8f4ab..ac70f00bac6 100644
--- a/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java
@@ -99,7 +99,7 @@ import java.util.function.Predicate;
* the {@code ConcurrentLinkedQueue} in another thread.
*
* This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @since 1.5
diff --git a/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentMap.java b/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentMap.java
index d301de9eee6..0a5cda1d81f 100644
--- a/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentMap.java
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentMap.java
@@ -61,7 +61,7 @@ import java.util.function.Function;
* the {@code ConcurrentMap} in another thread.
*
* This interface is a member of the
- *
+ *
* Java Collections Framework.
*
* @since 1.5
diff --git a/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentNavigableMap.java b/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentNavigableMap.java
index 0d763b6e9ea..5040e2ec4af 100644
--- a/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentNavigableMap.java
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentNavigableMap.java
@@ -43,7 +43,7 @@ import java.util.NavigableSet;
* and recursively so for its navigable sub-maps.
*
* This interface is a member of the
- *
+ *
* Java Collections Framework.
*
* @author Doug Lea
diff --git a/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java b/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java
index 2ae29aa42f3..8be87529539 100644
--- a/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java
@@ -106,7 +106,7 @@ import java.util.function.Predicate;
* elements.
*
* This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @author Doug Lea
diff --git a/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java b/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java
index 86be622c78b..d61fb2170cc 100644
--- a/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java
@@ -87,7 +87,7 @@ import java.util.Spliterator;
* distinguished from the absence of elements.
*
* This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @author Doug Lea
diff --git a/jdk/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java b/jdk/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java
index 63bd252868d..592f9a51cd2 100644
--- a/jdk/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java
@@ -82,7 +82,7 @@ import java.util.function.UnaryOperator;
* the {@code CopyOnWriteArrayList} in another thread.
*
* This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @since 1.5
diff --git a/jdk/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArraySet.java b/jdk/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArraySet.java
index 6e4ad018d2f..c8e984fab96 100644
--- a/jdk/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArraySet.java
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArraySet.java
@@ -87,7 +87,7 @@ import java.util.function.Predicate;
* }}
*
* This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @see CopyOnWriteArrayList
diff --git a/jdk/src/java.base/share/classes/java/util/concurrent/DelayQueue.java b/jdk/src/java.base/share/classes/java/util/concurrent/DelayQueue.java
index 50997f7abda..73d66b9e64c 100644
--- a/jdk/src/java.base/share/classes/java/util/concurrent/DelayQueue.java
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/DelayQueue.java
@@ -67,7 +67,7 @@ import java.util.concurrent.locks.ReentrantLock;
* particular order.
*
* This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @since 1.5
diff --git a/jdk/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java b/jdk/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java
index 1db30b3b440..ec7b7eee5ce 100644
--- a/jdk/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java
@@ -68,7 +68,7 @@ import java.util.function.Predicate;
* methods of the {@link Collection} and {@link Iterator} interfaces.
*
* This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @since 1.6
diff --git a/jdk/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java b/jdk/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java
index 7a1a2138073..368f6014dfa 100644
--- a/jdk/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java
@@ -71,7 +71,7 @@ import java.util.function.Predicate;
* methods of the {@link Collection} and {@link Iterator} interfaces.
*
* This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @since 1.5
diff --git a/jdk/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java b/jdk/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java
index 3a919c1efad..c7ad85b9fc1 100644
--- a/jdk/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java
@@ -81,7 +81,7 @@ import java.util.function.Predicate;
* the {@code LinkedTransferQueue} in another thread.
*
* This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @since 1.7
diff --git a/jdk/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java b/jdk/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java
index cdb1548eb61..8b0b3fec285 100644
--- a/jdk/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java
@@ -101,7 +101,7 @@ import java.util.function.Consumer;
* }}
*
* This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @since 1.5
diff --git a/jdk/src/java.base/share/classes/java/util/concurrent/SynchronousQueue.java b/jdk/src/java.base/share/classes/java/util/concurrent/SynchronousQueue.java
index 165198f97f8..0a4049b6628 100644
--- a/jdk/src/java.base/share/classes/java/util/concurrent/SynchronousQueue.java
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/SynchronousQueue.java
@@ -80,7 +80,7 @@ import java.util.concurrent.locks.ReentrantLock;
* methods of the {@link Collection} and {@link Iterator} interfaces.
*
* This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @since 1.5
diff --git a/jdk/src/java.base/share/classes/java/util/concurrent/TransferQueue.java b/jdk/src/java.base/share/classes/java/util/concurrent/TransferQueue.java
index 43d8f0c1395..0621bce2b76 100644
--- a/jdk/src/java.base/share/classes/java/util/concurrent/TransferQueue.java
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/TransferQueue.java
@@ -58,7 +58,7 @@ package java.util.concurrent;
* and {@code transfer} are effectively synonymous.
*
* This interface is a member of the
- *
+ *
* Java Collections Framework.
*
* @since 1.7
diff --git a/jdk/src/java.base/share/classes/java/util/package-info.java b/jdk/src/java.base/share/classes/java/util/package-info.java
index ab706e0d179..e6406f14d3d 100644
--- a/jdk/src/java.base/share/classes/java/util/package-info.java
+++ b/jdk/src/java.base/share/classes/java/util/package-info.java
@@ -29,7 +29,7 @@
* miscellaneous utility classes (a string tokenizer, a random-number
* generator, and a bit array).
*
- *
-The
-Java™ Virtual Machine Tools Interface (JVM TI)
-is a native tool interface provided in JDK 5.0 and newer.
-Native libraries that use JVM TI and are loaded into the
-Java Virtual Machine
-via the -agentlib, -agentpath, or -Xrun (deprecated) interfaces, are
-called Agents.
-
-JVM TI
-was designed to work with the
-Java Native Interface
-(JNI),
-and eventually displace the
-Java Virtual Machine Debugging Interface
-(JVMDI)
-and the
-Java Virtual Machine Profiling Interface
-(JVMPI).
-
-
-We have created a set of demonstration agents that should
-help show many of the features and abilities of the
-interface. This list of demonstration agents will change over time.
-They are provided as educational tools and as starting
-points for Java tool development.
-
-
-These agents are built with every JDK build and some basic testing is performed
-on a regular basis, but no extensive testbases currently
-exist for these agents.
-Every JDK installation should include all the pre-built binaries and sources for
-all these agents, just look in the demo/jvmti directory of your JDK.
-
-
-
-Using these agents will require the VM to locate the shared library file
-before any actual Java code is run.
-The JDK installation should contain all the agent libraries in
-the ${JAVA_HOME}/demo/jvmti/agent-name/lib directories.
-The Solaris 64bit version would be contained in the sparcv9 or amd64
-subdirectory.
-If 'java' complains that it can't find the library,
-you may need to add the directory containing the library into the
-LD_LIBRARY_PATH environment variable (Unix), or the PATH environment
-variable (Windows).
-This is system and platform specific.
-If you are using 64bit Solaris (e.g. 'java -d64'),
-you should use LD_LIBRARY_PATH64.
-Some agents such as the jdwp (debugger backend)
-are located inside the primary JDK directories and will always be found
-in those locations.
-
-
-The agents that instrument classfiles
-(i.e. BCI, usually through the java_crw_demo library)
-such as heapTracker, mtrace, and minst,
-also need to have the Java classes they use available in the bootclasspath.
-The agents will make attempts at automatically adding their jar file
-(e.g. heapTracker.jar, mtrace.jar, or minst.jar) to the bootclasspath
-with AddToBootstrapClassLoaderSearch from JVM TI at startup
-(see the agent_util code).
-This is done by locating this jar file at
-${JAVA_HOME}/demo/jvmti/agent-name
-where JAVA_HOME is obtained by calling GetSystemProperty from JVM TI
-with "java.home".
-We recognize that this is not ideal, but felt that as just demonstration
-code it was acceptable.
-Ideally the agent could find out the actual directory it came from and
-locate the jar file relative to that location.
-Our demonstration agents currently do not do this.
-
-
-If you choose to modify or change these agents, the above information
-is important in making everything is found.
-It is recommended that you change the name of the agent when you
-modify it to avoid conflicts with the existing demo agents.
-Or better yet, go to http://jdk.dev.java.net and submit your
-changes to the agent as an RFE to the JDK.
-
-
-
-All libraries loaded into java are assumed to be MT-safe (Multi-thread safe).
-This means that multiple threads could be executing the code at the same
-time, and static or global data may need to be placed in critical
-sections. See the Raw Monitor interfaces for more information.
-
-
-All native libraries loaded into the
-Java Virtual Machine,
-including Agent libraries,
-need to be compiled and built in a compatible way.
-Certain native compilation options or optimizations should be avoided,
-and some are required.
-More information on this options is available in the man pages for
-the various compilers.
-
-
-Some native compiler and linker options can create fatal or
-erroneous behavior when native agent libraries are operating
-inside the Java Virtual Machine.
-It would take too many words to describe all the possible issues with all
-the native compiler options, optimizations, and settings.
-Here are some recommendations on the basic compiler and linker options
-we recommend:
-
-
-Remember, the complete source to all these agents is contained in the JDK
-installations at demo/jvmti.
-
-
-For more detailed information on JVM TI, refer to
-
-http://java.sun.com/j2se/latest/docs/guide/jvmti.
-
-
-More information on using JNI and building native libraries refer to:
-
-http://java.sun.com/j2se/latest/docs/guide/jni.
-
-
-Additional information can also be found by doing a search on "jvmti" at
-http://java.sun.com/j2se.
-Various technical articles are also available through this website.
-And don't forget the
-Java Tutorials at
-http://docs.oracle.com/javase/tutorial
-for getting a quick start on all the various interfaces.
-
-
-Comments regarding JVM TI or on any of these demonstrations should be
-sent through
-http://java.sun.com/mail/
-
-
-
-
diff --git a/jdk/src/demo/share/jvmti/java_crw_demo/README.txt b/jdk/src/demo/share/jvmti/java_crw_demo/README.txt
deleted file mode 100644
index c242793a6a2..00000000000
--- a/jdk/src/demo/share/jvmti/java_crw_demo/README.txt
+++ /dev/null
@@ -1,77 +0,0 @@
-#
-# Copyright (c) 2004, 2007, Oracle and/or its affiliates. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# - Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-#
-# - Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-#
-# - Neither the name of Oracle nor the names of its
-# contributors may be used to endorse or promote products derived
-# from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
-# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
-# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-java_crw_demo Library
-
-The library java_crw_demo is a small C library that is used by HPROF
-and other agent libraries to do some very basic bytecode
-insertion (BCI) of class files. This is not an agent
-library but a general purpose library that can be used to do some
-very limited bytecode insertion.
-
-In the demo sources, look for the use of java_crw_demo.h and
-the C function java_crw_demo(). The java_crw_demo library is provided
-as part of the JRE.
-
-The basic BCI that this library does includes:
-
- * On entry to the java.lang.Object init method (signature "()V"),
- a invokestatic call to tclass.obj_init_method(object); is inserted.
-
- * On any newarray type opcode, immediately following it, the array
- object is duplicated on the stack and an invokestatic call to
- tclass.newarray_method(object); is inserted.
-
- * On entry to all methods, a invokestatic call to
- tclass.call_method(cnum,mnum); is inserted. The agent can map the
- two integers (cnum,mnum) to a method in a class, the cnum is the
- number provided to the java_crw_demo library when the classfile was
- modified.
-
- * On return from any method (any return opcode), a invokestatic call to
- tclass.return_method(cnum,mnum); is inserted.
-
-Some methods are not modified at all, init methods and finalize methods
-whose length is 1 will not be modified. Classes that are designated
-"system" will not have their clinit methods modified. In addition, the
-method java.lang.Thread.currentThread() is not modified.
-
-No methods or fields will be added to any class, however new constant
-pool entries will be added at the end of the original constant pool table.
-The exception, line, and local variable tables for each method is adjusted
-for the modification. The bytecodes are compressed to use smaller offsets
-and the fewest 'wide' opcodes.
-
-All attempts are made to minimize the number of bytecodes at each insertion
-site, however, classes with N return opcodes or N newarray opcodes will get
-N insertions. And only the necessary modification dictated by the input
-arguments to java_crw_demo are actually made.
-
diff --git a/jdk/src/demo/share/jvmti/java_crw_demo/java_crw_demo.c b/jdk/src/demo/share/jvmti/java_crw_demo/java_crw_demo.c
deleted file mode 100644
index eaa271e9e18..00000000000
--- a/jdk/src/demo/share/jvmti/java_crw_demo/java_crw_demo.c
+++ /dev/null
@@ -1,2535 +0,0 @@
-/*
- * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-
-/* Class reader writer (java_crw_demo) for instrumenting bytecodes */
-
-/*
- * As long as the callbacks allow for it and the class number is unique,
- * this code is completely re-entrant and any number of classfile
- * injections can happen at the same time.
- *
- * The current logic requires a unique number for this class instance
- * or (jclass,jobject loader) pair, this is done via the ClassIndex
- * in hprof, which is passed in as the 'unsigned cnum' to java_crw_demo().
- * It's up to the user of this interface if it wants to use this
- * feature.
- *
- */
-
-#include
-Comments regarding java.lang.management API or on any of these
-demonstrations should be sent through
-http://java.sun.com/mail/
-
-
-
diff --git a/jdk/src/demo/share/scripting/jconsole-plugin/README.txt b/jdk/src/demo/share/scripting/jconsole-plugin/README.txt
deleted file mode 100644
index fc4bbf199aa..00000000000
--- a/jdk/src/demo/share/scripting/jconsole-plugin/README.txt
+++ /dev/null
@@ -1,64 +0,0 @@
-What is this demo about?
-
-This is "script shell" plugin for jconsole - the monitoring and management
-client tool shipped with JRE. This plugin adds "Script Shell" tab to jconsole.
-This serves as a demo for jconsole plugin API (com.sun.tools.jconsole) as well
-as a demo for scripting API (javax.script) for the Java platform.
-
-Script console is an interactive read-eval-print interface that can be used
-used to execute advanced monitoring and management queries. By default,
-JavaScript is used as the scripting language. The scripting language can be
-changed using the system property com.sun.demo.jconsole.console.language. To
-use other scripting languages, you need to specify the corresponding engine
-jar file in pluginpath along with this plugin's jar file.
-
-The following 3 global variables are exposed to the script engine:
-
- window javax.swing.JPanel
- engine javax.script.ScriptEngine
- plugin com.sun.tools.jconsole.JConsolePlugin
-
-If you use JavaScript, there are many useful global functions defined in
-./src/resources/jconsole.js. This is built into the script plugin jar file.
-In addition, you can add other global functions and global variables by
-defining those in ~/jconsole.js (or jconsole. [ Introduction to this package. ]
- **/
-
-public class LinkedQueue {
-
-
- /**
- * Dummy header node of list. The first actual node, if it exists, is always
- * at head_.next. After each take, the old first node becomes the head.
- **/
- protected LinkedNode head_;
- protected int count_;
- /**
- * Helper monitor for managing access to last node, in case it is also first.
- * last_ and waitingForTake_ ONLY used with synch on appendMonitor_
- **/
- protected final Object lastMonitor_ = new Object();
-
- /**
- * The last node of list. Put() appends to list, so modifies last_
- **/
- protected LinkedNode last_;
-
- /**
- * The number of threads waiting for a take.
- * Notifications are provided in put only if greater than zero.
- * The bookkeeping is worth it here since in reasonably balanced
- * usages, the notifications will hardly ever be necessary, so
- * the call overhead to notify can be eliminated.
- **/
- protected int waitingForTake_ = 0;
-
- public LinkedQueue() {
- head_ = new LinkedNode(null);
- last_ = head_;
- count_ = 0;
- }
-
- /** Main mechanics for put/offer **/
- protected void insert(Object x) {
- synchronized(lastMonitor_) {
- LinkedNode p = new LinkedNode(x);
- last_.next = p;
- last_ = p;
- count_++;
- if (count_ > 1000 && (count_ % 1000 == 0))
- System.out.println("In Queue : " + count_);
- if (waitingForTake_ > 0)
- lastMonitor_.notify();
- }
- }
-
- /** Main mechanics for take/poll **/
- protected synchronized Object extract() {
- Object x = null;
- LinkedNode first = head_.next;
- if (first != null) {
- x = first.value;
- first.value = null;
- head_ = first;
- count_ --;
- }
- return x;
- }
-
-
- public void put(Object x) throws InterruptedException {
- if (x == null) throw new IllegalArgumentException();
- if (Thread.interrupted()) throw new InterruptedException();
- insert(x);
- }
-
- public boolean offer(Object x, long msecs) throws InterruptedException {
- if (x == null) throw new IllegalArgumentException();
- if (Thread.interrupted()) throw new InterruptedException();
- insert(x);
- return true;
- }
-
- public Object take() throws InterruptedException {
- if (Thread.interrupted()) throw new InterruptedException();
- // try to extract. If fail, then enter wait-based retry loop
- Object x = extract();
- if (x != null)
- return x;
- else {
- synchronized(lastMonitor_) {
- try {
- ++waitingForTake_;
- for (;;) {
- x = extract();
- if (x != null) {
- --waitingForTake_;
- return x;
- }
- else {
- lastMonitor_.wait();
- }
- }
- }
- catch(InterruptedException ex) {
- --waitingForTake_;
- lastMonitor_.notify();
- throw ex;
- }
- }
- }
- }
-
- public synchronized Object peek() {
- LinkedNode first = head_.next;
- if (first != null)
- return first.value;
- else
- return null;
- }
-
-
- public synchronized boolean isEmpty() {
- return head_.next == null;
- }
-
- public Object poll(long msecs) throws InterruptedException {
- if (Thread.interrupted()) throw new InterruptedException();
- Object x = extract();
- if (x != null)
- return x;
- else {
- synchronized(lastMonitor_) {
- try {
- long waitTime = msecs;
- long start = (msecs <= 0)? 0 : System.currentTimeMillis();
- ++waitingForTake_;
- for (;;) {
- x = extract();
- if (x != null || waitTime <= 0) {
- --waitingForTake_;
- return x;
- }
- else {
- lastMonitor_.wait(waitTime);
- waitTime = msecs - (System.currentTimeMillis() - start);
- }
- }
- }
- catch(InterruptedException ex) {
- --waitingForTake_;
- lastMonitor_.notify();
- throw ex;
- }
- }
- }
- }
-
- class LinkedNode {
- Object value;
- LinkedNode next = null;
- LinkedNode(Object x) { value = x; }
- LinkedNode(Object x, LinkedNode n) { value = x; next = n; }
- }
-}
diff --git a/jdk/src/demo/solaris/jni/Poller/Poller.c b/jdk/src/demo/solaris/jni/Poller/Poller.c
deleted file mode 100644
index 5c627ac57ca..00000000000
--- a/jdk/src/demo/solaris/jni/Poller/Poller.c
+++ /dev/null
@@ -1,753 +0,0 @@
-/*
- * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-
-/*
- **********************************************************************
- * Poller.c :
- * JNI code for use with Poller.java, principally to take advantage
- * of poll() or /dev/poll multiplexing.
- *
- * One will need Solaris 8 or Solaris 7 with adequate patches to take
- * advantage of the /dev/poll performance enhancements, though any
- * version of Solaris 7 will automatically use the kernel poll()
- * caching. And poll() will function in 2.5.1 and 2.6 as well, but
- * will not perform well for large numbers of file descriptors.
- *
- * Several assumptions have been made to simplify this code :
- * 1> At most MAX_HANDLES (32) separate pollable entities are currently
- * supported.
- * 2> Global synchronization from Java is assumed for all init, create
- * and destroy routines. Per Object (handle passed in) synchronization
- * is required for all AddFd, RemoveFd, IsMember, and Wait routines.
- * 3> It is currently up to the user to handle waking up an
- * existing nativeWait() call to do an addfd or removefd on
- * that set...could implement that here with an extra pipe, or
- * with a pair of loopback sockets in Poller.java or user code.
- * In most cases interruption is not necessary for deletions,
- * so long as deletions are queued up outside the Poller class
- * and then executed the next time waitMultiple() returns.
- * 4> /dev/poll performance could be slightly improved by coalescing
- * adds/removes so that a write() is only done before the ioctl
- * (DP_POLL), but this complicates exception handling and sees
- * only modest performance gains so wasn't done.
- * 5> /dev/poll does not report errors on attempts to remove non-
- * extant fds, but a future bug fix to the /dev/poll device driver
- * should solve this problem.
- * 6> Could add simpler code for pre-Solaris 7 releases which will
- * perform slightly better on those OSs. But again there
- * are only modest gains to be had from these new code paths,
- * so they've been omitted here.
- *
- * Compile "cc -G -o
- This demo shows how to use repeating annotations at runtime and at compile time.
-
- Shows how to define repeating annotations and process them at compile time.
- The problem domain is some code that performs useful operations on hardware devices.
- The code relies on "modules" to be present on the devices. Applicability of the code to a particular
- device is checked while compiling the code for a particular device.
- A set of modules provided by a device is listed in an xml file that turns red during the compilation
- phase and is compared with the required module set specified by annotations.
- For instance, there is kettle with hardware modules: thermometer, display, and clock.
- There is also a boiler plug-in that requires clock, thermometer, heater, and optionally an LED light.
-
- Build the PluginChecker annotation processor first.
- Then, run javac with the annotation processor against plug-in sources using the following command:
- where
- Shows how to define repeating annotations and process them at runtime.
- A problem domain is code that needs to validate provided Suppliers for conformance to some criteria.
- The criteria are implemented by the Validator class which is applied by using annotations that are placed in
- the code whenever validation is needed. For more information, see the
- source files.
-
- The JMX scandir example is an application that
- scans parts of a filesystem - e.g. a set of directories
- used by a number of lab machines when running tests - in
- order to clean up and optimize disk space by removing
- obsolete files - e.g. files that are leaked by the test
- suites running on those machines, like coredump files, or
- temporary files that might remain after a test crash.
- It could also serve as a basis for an application that
- would monitor disk usage and suggest removal of old big
- long-unaccessed files.
- The JMX scandir example does not however implement
- the full fledged logic that such an application might
- have. It implements a subset of this logic which is
- sufficient to demonstrate common patterns and
- solutions used when implementing a monitoring and
- management interface for an application with JMX
- Technology. This example is an advanced JMX example, which presents
- advanced JMX concepts. It is assumed that the reader is already
- familiar with the JMX API. Newcomers to JMX Technology are
- invited to have a look at the JMX API Overview, Tutorial and Examples before going any further.
- In order to build the example,
- you may need to copy the jmx-scandir
- directory to somewhere where you have write permissions.
- If you wish to run the testsuite from within the NetBeans IDE you will also have
- to set the libs.junit.classpath variable in
- build.properties.
- The libs.junit.classpath variable should point to your
- junit.jar,
- version 3.8.1 or 3.8.2.
- Table Of Contents: Before reading further, you will need to generate the
- Java Documentation for the example's sources. In the example root directory (where the Alternatively you can open the jmx-scandir project with the
- NetBeans IDE and generate the Javadoc from its If building the documentation fails, please make sure to read the
- note at the beginning of this document. The JMX scandir example is built around the
- following MBeans: An application When the The application's default XML config file is determined as
- follows:
- It is worth noting that this project is defined to
- run with the following properties:
- Once generated, the Javadoc of example classes can
- be found starting from You can view the sources in the This section discusses some common patterns and
- design choices that this example demonstrates, and some pitfalls that
- it avoids.
- What is an MXBean? MXBeans made their appearance in
- J2SE 5.0 (Tiger), with the Management and Monitoring
- API of the JVM. However, Java SE 6 is the first
- Java SE release that contains a standard framework which
- makes it possible to create and register your own MXBeans.
- MXBeans are a special kind of MBean, which once registered
- in the MBeanServer, get automatically transformed into
- OpenMBeans. From a developer point of view, nothing changes:
- A Wombat MBean can become an MXBean simply by renaming
- its Using MXBeans rather than plain Standard MBean brings its
- own advantages: In short, MXBeans are so much easier to use that
- this example doesn't even have a single regular
- Standard MBean.
- See also What is an MXBean?
- and Inter-MXBean References.
- As you must know if you've been studying JMX, MBeans are
- named objects. The names of MBeans are represented by
- instances of In this example, we are following the rules
- for ObjectName suggested in the JMX Best Practices: The rules listed above are implemented by a couple
- of static helper functions in the ScanManager class. See the code of the
- One of the most common problems that needs to be solved
- when designing a management interface with JMX is to
- choose a representation for inter-MBean relationships. In Java 6, these three possibilities still remain, but
- the new MXBean framework brings up an interesting
- alternative. Instead of returning an ObjectName or
- an ObjectName array, an MXBean can return a proxy
- to its related MXBeans. This is how we have chosen to
- implement our inter MBean relationships in this
- example:
-
- The additional benefit, as compared to returning ObjectNames or
- using the RelationService is that interface type of the MBeans
- which are pointed to by the relationship becomes directly
- apparent. The method:
- However, it must be clear that the behaviour will be
- quite different when an MXBean is returned as compared
- to when a simple bean is returned.
- When an MXBean is returned, the remote client sees either
- an ObjectName, if it is a generic client like jconsole, or
- a proxy to a remote MXBean, if the client is working with the
- MXBean interface. Invoking an operation on one of the
- proxy returned by a method such as
- If It is worth noting that although an MXBean interface
- can have getters and operations which return an MXBean
- interface, a regular standard MBean shouldn't have
- any getters or methods which return MBean interfaces or
- MXBean interfaces.
- For more information see also Inter-MXBean References.
-
- Sometimes, an MBean needs to have a reference to the
- MBeanServer in which it is registered, or needs to know
- with which ObjectName it has been registered.
-
- Sometimes also, an MBean may need to perform some
- checks before being registered, or will need
- to carry out some actions right after it has been
- successfully registered in the MBeanServer.
-
- Sometimes again, an MBean may need to perform some
- checks, or some cleaning actions, just before, or
- just after, it is unregistered.
-
- When an MBean has such needs, the easiest solution
- for it is to implement the The
- When an MBean implementing this interface is created
- (with
- Most of the MXBeans we have defined in this example
- implement the
- A singleton MBean is an MBean which can only have one
- instance registered in a given MBeanServer. There are already quite a few examples of singleton
- MBeans in the java.lang.management API. The
- ThreadingMXBean, ClassLoadingMXBean, RuntimeMXBean, etc.
- are all singleton MBeans.
- In this example, we have two singleton MBeans:
- The The
- On the other hand, the Note that all singleton MBean names in this example
- are created using the A common task that many JMX applications have
- is to manage the life cycle of MBeans registered
- in the MBeanServer. In this example, we have decided to follow a simple
- pattern: The You will note that the Handling the LifeCycle of all the application's
- MBeans in a single MBean is usually a good design
- pattern, especially if the application is a
- module which is intended to share a JVM - or
- an MBeanServer - with other modules.
- This is specially useful if the application needs to
- be loaded and unloaded on demand: in that
- case, simply registering or unregistering the top level
- MBean (in our example the In order to emit notifications, an MBean must be
- an instance of It is worth noting that the MBean may not be
- invoked each time a JMX client wants to register
- a listener. For instance, the RMIConnectorServer
- registers only once a single listener with each MBean
- which is a An MBean can therefore make no assumption about
- which client or how many clients have registered for
- notifications.
- It is also worth noting that the logic of the
- methods defined in There are actually three ways for an MBean to
- implement This is the simplest way of coding an MBean which
- is a Simply extend In our example, both the ScanDirConfigMXBean and ResultLogManagerMXBean extend
- There may be cases however where delegating to a
- wrapped For instance, if your MBeans already derive from
- some base class, extending Similarly, if you do not want to have the inherited
- In our example both the ScanManagerMXBean and the DirectoryScannerMXBean use the delegation
- pattern rather than extending
- It may be also worth noting that some tools like
- the JMX Module of NetBeans IDE, will be able to
- generate for you all the code that delegates to a
- wrapped This is the last possibility for an MBean that
- needs to send notifications: simply implement
- One thing you must keep in mind when sending
- notifications is not to send them from within
- a synchronized block, or while holding a lock on
- some resource. Indeed, what happens when you send a notification
- may vary greatly depending on whether the client
- which has registered for notifications has done
- so through a In this latter case, the listener will be invoked
- synchronously in the same thread that your MBean is
- using to send its notification. If by misfortune, the
- code of that listener now re-enters your MBean through a
- call that flows through a JMXConnector, a deadlock
- could occur. It is therefore very important to release
- any lock you may have before calling
- An easy way to do that is demonstrated in the
- In our example the Another common best practice when you want
- to improve interoperability is to use directly
- the Notification base classes provided in the
- JMX™ API. Do not create your own
- subclasses of these standard classes.
- Indeed, if you code your own subclass, a generic
- client, like jconsole, will not be able to receive
- that notification unless it has that custom
- subclass in its classpath.
-
- If you want your application to be interoperable, it is
- therefore preferable not to subclass any of the standard
- Notification classes. You can define your own
- Notification type string, and if you need to send
- additional data, you can put a CompositeData, or a
- HashMap of serializable standard types in the
- Notification's user data fields.
- In this example, we are using directly the
- standard notification classes:
- Careful readers will have noted that the ScanManagerMXBean and the DirectoryScannerMXBean both use the
- In fact, this is because the semantics of these
- notifications is not exactly the same - although
- both denote a state change:
- In the case of In the case of the A common practice when designing a management application is
- to have an MBean, or a set of MBeans, dedicated to configuration.
- Separating configuration from control and monitoring allows
- more appropriate logic, and often simplifies the design and
- implementation of the management interface.
-
- In our example, the ScanDirConfigMXBean is dedicated to the application configuration.
- The In this way, all configurations aspects are gathered and concentrated
- inside the In order to save and store the application configuration data, the
- It is worth noting that these same beans can also be handled by the
- MXBean framework (our beans don't contain recursive data structures) and can
- therefore be used directly as attributes and parameters of MXBeans, without
- needing to be Java-serializable (the MXBean framework transform them in
- CompositeData objects - which are serializable).
- The same ScanManagerConfig bean that we use to read from and write to the
- XML configuration file is thus also used as attribute of the ScanDirConfigMXBean. It is transformed into a A question often asked by newcomers to JMX technology
- is whether the MBeanServer is thread-safe. Well, the MBeanServer is
- thread safe, but it doesn't put any locks on the MBeans it contains. The
- MBeans can be concurrently accessed by multiple threads, and must therefore
- take care of their own thread safety.
- In this example, we have been using two methods to ensure thread
- safety for our MBeans: synchronized blocks, and semaphores.
- Using synchronized blocks is probably the most common and easiest way
- to implement thread safety in Java. When dealing with MBeans though, here
- are a couple of rules to keep in mind:
- Another means of implementing thread-safe code is to use semaphores.
- The ScanManagerMXBean uses a semaphore called
- Using It is worth noting that each of these techniques has its own
- advantages and disadvantages - which can make one of them more or less
- appropriate depending on the inner logic of the MBean you're implementing.
- Careful readers will also have noted that we used
- Implementing code that needs to wait for notifications is sometimes
- difficult. Because notifications are asynchronous, doing something
- like:
- You will note that this is a technique we've been using in the ScanDirAgent class and in the example unit tests.
- We have seen that MXBeans will let you return proxy references to other
- MXBeans. But should that MXBean hold a direct reference to the MXBeans it
- relates to, or would it be better for it to hold only a proxy?
-
- As a general rule it is better when an MBean reference is
- only held by the MBeanServer. It is a better design
- to hold a reference to a proxy, rather than to hold
- a hard reference to an MBean. However there are two cases
- when holding a hard reference might be preferred:
- In our example, the ScanManagerMXBean holds only proxy references to the ScanDirConfigMXBean and the DirectoryScannerMXBeans. The ScanDirAgent is the Agent class for the scandir application.
- This class contains the The
- When the Standalone JMX applications usually have an Agent class that contain
- their The ScanDirClient is an example class that shows how a
- programmatic client can connect to a secured scandir application.
- This class contains a How to secure a JMX scandir application and run
- the secure The Make sure that you have access to junit.jar (either 3.8.1 or 3.8.2).
- Make sure also that you have junit.jar in your
- Alternatively you can open the jmx-scandir project with the
- NetBeans IDE and test the jmx-scandir project from the
- In the example root directory (where the This will run the example using the configuration
- file provided in the src/etc directory.
- Alternatively you can open the jmx-scandir project with the
- NetBeans IDE. You can run the example by
- selecting the When the application is started, you can connect to
- it with jconsole.
- Open the MBeans tab, and look for the
- Now go to the You can see that the notifications counter was
- incremented by three: you have just scheduled,
- run, and completed a batch of directory scans.
- Now go to the Package Specification
+ * {@index "Java Collections Framework"}
*
*
-JVM TI Demonstration Code
-
-Using or Running These Agents
-
- Demonstration Agents Available
-
-
-
-
-
-
-
-
-This is a extremely small agent that does nothing but check the
-version string supplied in the jvmti.h file, with the version
-number supplied by the VM at runtime.
-
-This is a small agent that traces CompiledMethodLoad events along
-with the HotSpot specific compile_info parameter.
-
-This is a small agent that does method tracing.
-It uses Bytecode Instrumentation (BCI) via the java_crw_demo library.
-
-This is an even smaller agent that does just method entry tracing.
-It also uses Bytecode Instrumentation (BCI) via the java_crw_demo library,
-but the instrumentation code is pure Java (no Java native methods used).
-NOTE: Be sure to check out java.lang.instrument for a way to avoid
-native code agents completely.
-
-This is a small agent that does garbage collection counting.
-
-This is a small agent that does some basic heap inspections.
-
-This is a small agent that does BCI to capture object creation
-and track them.
-It uses Bytecode Instrumentation (BCI) via the java_crw_demo library.
-
-This is a small agent that gets information about threads
-waiting on monitors.
-Agent Support
-
-
-
-
-
-
-
-
-This is a demo C library that does class file to class file
-transformations or BCI (Bytecode Instrumentation).
-It is used by several of the above agents.
-Native Library Build Hints
-
-
-
-
- Solaris
-
-
-For 32bit SPARC:
-
-
-cc -xO2 -mt -xregs=no%appl -xmemalign=4s -xarch=v8 -KPIC -c *.c
-
-cc -mt -xarch=v8 -z defs -ztext -G -o libXXX.so *.o -lc
-
-For 64bit SPARC:
-
-
-cc -xO2 -mt -xregs=no%appl -xarch=v9 -KPIC -c *.c
-
-cc -mt -xarch=v9 -z defs -ztext -G -o libXXX.so *.o -lc
-
-For X86:
-
-
-
-cc -xO2 -mt -xregs=no%frameptr -KPIC -c *.c
-
-cc -mt -z defs -ztext -G -o libXXX.so *.o -lc
-
-For AMD64:
-
-
-
-cc -xO2 -mt -xregs=no%frameptr -xarch=amd64 -KPIC -c *.c
-
-cc -mt -xarch=amd64 -z defs -ztext -G -o libXXX.so *.o -lc
-
-
-
--xarch=v8,
-for SPARC 64bit use -xarch=v9,
-for X86 (32-bit)
-
-leave the option off or use -xarch=generic
-,
-and for AMD64 (64bit) use -xarch=amd64
-with both C and C++.
-
-This is to be specific as to the architecture and the file format
-of the .o files (and ultimately of the .so).
--KPIC -mt
-with both C and C++.
--xregs=no%appl and for X86 and AMD64 use -xregs=no%frameptr
-with both C and C++.
--xmemalign=4
-with both C and C++.
-ldd -r LibraryName.
-
-After the shared library has been built, the utility
-ldd can be used to verify that all dependent libraries
-have been satisfied, and all externs can be found.
-If ldd says anything is missing, it is very likely that the JVM will also
-be unable to load this library.
-This usually means that you missed some -lname
-options when building the library, or perhaps forgot a -R path
-option that tells the library where to look for libraries at runtime.
- Linux
-
-
-For X86:
-
-
-
-gcc -O2 -fPIC -pthread -DLINUX -c *.c
-
-gcc -z defs -static-libgcc -shared -o libXXX.so *.o -lc
-
-For AMD64:
-
-
-
-gcc -O2 -fPIC -pthread -DLINUX -D_LP64=1 -c *.c
-
-gcc -z defs -static-libgcc -shared -o libXXX.so *.o -lc
-
--fPIC -pthread.
--fno-omit-frame-pointer.
-
-It is important that these libraries have frame pointer register usage, see the above comments on the Solaris
--xregs=no%frameptr
-option.
-
-When building the shared library (-shared option), this option
-allows for maximum portability of the library between different
-flavors of Linux.
-The problem we have seen with Linux is that we cannot depend
-on a compatible shared gcc library existing on all the versions of
-Linux we can run on.
-By doing this static link, the version script becomes more
-important, making sure you don't expose any extern symbols
-you didn't intend to.
-ldd -r LibraryName.
-
-Provides the same checking as Solaris (see above).
- Windows
-
-
-For X86:
-
-
-
-cl /O1 /MD /D _STATIC_CPPLIB /c *.c
-
-link /dll /opt:REF /out:XXX.dll *.obj
-
-For AMD64:
-
-
-
-cl /O1 /MD /D _STATIC_CPPLIB /c *.c
-
-link /dll /opt:REF /out:XXX.dll *.obj
-
-/opt:REF when building the dll.
-/MD /D _STATIC_CPPLIB option.
-
-This causes your dll to become dependent on just MSVCR*.DLL.
-The option /D _STATIC_CPPLIB prevents you from becoming dependent on the
-C++ library MSVCP*.DLL.
-This is what we use in the JDK, but there are probably many combinations
-that you could safely use, unfortunately there are many combinations
-of runtimes that will not work.
-Check the Microsoft site on proper use of runtimes.
-dumpbin /exports and the VC++ "Dependency Walker".
-
-Provides dependency information similar to ldd.
-For More Information
-
-Comments and Feedback
-
->,Object> {
- private MyTableModel tmodel;
- Worker(MyTableModel tmodel) {
- this.tmodel = tmodel;
- }
-
- // Get the current thread info and CPU time
- @Override
- public List
java.lang.management Demonstration Code
-
-
-
-
-
-
-
-
-Shows how to get thread dumps and look for deadlocks.
-
-Shows how you can find out about Garbage Collection in the VM.
-
-Shows how you can find out the memory usage in the VM.
-
-Shows how you can find out the threads with top CPU usage.
-Comments and Feedback
-
-Poller object.
- * Native code uses sysconf(_SC_OPEN_MAX) to determine how
- * many fd/skt objects this Poller object can contain.
- */
- public Poller() throws Exception {
- synchronized(globalSync) {
- this.handle = nativeCreatePoller(-1);
- }
- }
-
- /**
- * Constructs an instance of a Poller object.
- * @param maxFd the maximum number of FileDescriptors/Sockets
- * this Poller object can contain.
- */
- public Poller(int maxFd) throws Exception {
- synchronized(globalSync) {
- this.handle = nativeCreatePoller(maxFd);
- }
- }
-
- /**
- * Needed to clean up at the JNI C level when object is GCd.
- */
- protected void finalize() throws Throwable {
- synchronized(globalSync) {
- nativeDestroyPoller(handle);
- super.finalize();
- }
- }
-
- /**
- * Since we can't guarantee WHEN finalize is called, we may
- * recycle on our own.
- * @param maxFd the maximum number of FileDescriptors/Sockets
- * this Poller object can contain.
- */
- public void reset(int maxFd) throws Exception {
- synchronized(globalSync) {
- nativeDestroyPoller(handle);
- this.handle = nativeCreatePoller(maxFd);
- }
- }
- /**
- * Since we can't guarantee WHEN finalize is called, we may
- * recycle on our own.
- */
- public void reset() throws Exception {
- synchronized(globalSync) {
- nativeDestroyPoller(handle);
- this.handle = nativeCreatePoller(-1);
- }
- }
-
- /**
- * Add FileDescriptor to the set handled by this Poller object.
- *
- * @param fdObj the FileDescriptor, Socket, or ServerSocket to add.
- * @param event the bitmask of events we are interested in.
- * @return the OS level fd associated with this IO Object
- * (which is what waitMultiple() stores in fds[])
- */
- public synchronized int add(Object fdObj, short event) throws Exception {
- return nativeAddFd(handle,findfd(fdObj), event);
- }
-
- /**
- * Remove FileDescriptor from the set handled by this Poller object.
- *
- * Must be called before the fd/skt is closed.
- * @param fdObj the FileDescriptor, Socket, or ServerSocket to remove.
- * @return true if removal succeeded.
- */
- public synchronized boolean remove(Object fdObj) throws Exception {
- return (nativeRemoveFd(handle,findfd(fdObj)) == 1);
- }
- /**
- * Check if fd or socket is already in the set handled by this Poller object
- *
- * @param fdObj the FileDescriptor or [Server]Socket to check.
- * @return true if fd/skt is in the set for this Poller object.
- */
- public synchronized boolean isMember(Object fdObj) throws Exception {
- return (nativeIsMember(handle,findfd(fdObj)) == 1);
- }
- /**
- * Wait on Multiple IO Objects.
- *
- * @param maxRet the maximum number of fds[] and revents[] to return.
- * @param fds[] (return) an array of ints in which to store fds with
- * available data upon a successful non-timeout return.
- * fds.length must be >= maxRet
- * @param revents[] (return) the actual events available on the
- * same-indexed fds[] (i.e. fds[0] has events revents[0])
- * revents.length must be >= maxRet
- *
- * Note : both above arrays are "dense," i.e. only fds[] with events
- * available are returned.
- *
- * @param timeout the maximum number of milliseconds to wait for
- * events before timing out.
- * @return the number of fds with triggered events.
- *
- * Note : convenience methods exist for skipping the timeout parameter
- * or the maxRet parameter (in the case of no maxRet, fds.length
- * must equal revents.length)
- *
- * obj.waitMultiple(null,null,timeout) can be used for pausing the LWP
- * (much more reliable and scalable than Thread.sleep() or Object.wait())
- */
- public synchronized int waitMultiple(int maxRet, int[] fds,short[] revents,
- long timeout) throws Exception
- {
- if ((revents == null) || (fds == null)) {
- if (maxRet > 0) {
- throw new NullPointerException("fds or revents is null");
- }
- } else if ( (maxRet < 0) ||
- (maxRet > revents.length) || (maxRet > fds.length) ) {
- throw new IllegalArgumentException("maxRet out of range");
- }
-
- int ret = nativeWait(handle, maxRet, fds, revents, timeout);
- if (ret < 0) {
- throw new InterruptedIOException();
- }
- return ret;
- }
-
- /**
- * Wait on Multiple IO Objects (no timeout).
- * A convenience method for waiting indefinitely on IO events
- *
- * @see Poller#waitMultiple
- *
- */
- public int waitMultiple(int maxRet, int[] fds, short[] revents)
- throws Exception
- {
- return waitMultiple(maxRet, fds, revents,-1L); // already synchronized
- }
-
- /**
- * Wait on Multiple IO Objects (no maxRet).
- * A convenience method for waiting on IO events when the fds
- * and revents arrays are the same length and that specifies the
- * maximum number of return events.
- *
- * @see Poller#waitMultiple
- *
- */
- public synchronized int waitMultiple(int[] fds, short[] revents,
- long timeout) throws Exception
- {
- if ((revents == null) && (fds == null)) {
- return nativeWait(handle,0,null,null,timeout);
- } else if ((revents == null) || (fds == null)) {
- throw new NullPointerException("revents or fds is null");
- } else if (fds.length == revents.length) {
- return nativeWait(handle, fds.length, fds, revents, timeout);
- }
- throw new IllegalArgumentException("fds.length != revents.length");
- }
-
-
- /**
- * Wait on Multiple IO Objects (no maxRet/timeout).
- * A convenience method for waiting on IO events when the fds
- * and revents arrays are the same length and that specifies the
- * maximum number of return events, and when waiting indefinitely
- * for IO events to occur.
- *
- * @see Poller#waitMultiple
- *
- */
- public int waitMultiple(int[] fds, short[] revents)
- throws Exception
- {
- if ((revents == null) || (fds == null)) {
- throw new NullPointerException("fds or revents is null");
- } else if (fds.length == revents.length) {
- return waitMultiple(revents.length,fds,revents,-1L); // already sync
- }
- throw new IllegalArgumentException("fds.length != revents.length");
- }
-
- // Utility - get (int) fd from FileDescriptor or [Server]Socket objects.
-
- private int findfd(Object fdObj) throws Exception {
- Class cl;
- Field f;
- Object val, implVal;
-
- if ((fdObj instanceof java.net.Socket) ||
- (fdObj instanceof java.net.ServerSocket)) {
- cl = fdObj.getClass();
- f = cl.getDeclaredField("impl");
- f.setAccessible(true);
- val = f.get(fdObj);
- cl = f.getType();
- f = cl.getDeclaredField("fd");
- f.setAccessible(true);
- implVal = f.get(val);
- cl = f.getType();
- f = cl.getDeclaredField("fd");
- f.setAccessible(true);
- return ((Integer) f.get(implVal)).intValue();
- } else if ( fdObj instanceof java.io.FileDescriptor ) {
- cl = fdObj.getClass();
- f = cl.getDeclaredField("fd");
- f.setAccessible(true);
- return ((Integer) f.get(fdObj)).intValue();
- }
- else {
- throw new IllegalArgumentException("Illegal Object type.");
- }
- }
-
- // Actual NATIVE calls
-
- private static native int nativeInit();
- private native int nativeCreatePoller(int maxFd) throws Exception;
- private native void nativeDestroyPoller(int handle) throws Exception;
- private native int nativeAddFd(int handle, int fd, short events)
- throws Exception;
- private native int nativeRemoveFd(int handle, int fd) throws Exception;
- private native int nativeRemoveIndex(int handle, int index)
- throws Exception;
- private native int nativeIsMember(int handle, int fd) throws Exception;
- private native int nativeWait(int handle, int maxRet, int[] fds,
- short[] events, long timeout)
- throws Exception;
- /**
- * Get number of active CPUs in this machine
- * to determine proper level of concurrency.
- */
- public static native int getNumCPUs();
-
- static {
- System.loadLibrary("poller");
- nativeInit();
- }
-}
diff --git a/jdk/src/demo/solaris/jni/Poller/PollingServer.java b/jdk/src/demo/solaris/jni/Poller/PollingServer.java
deleted file mode 100644
index 5cb26260398..00000000000
--- a/jdk/src/demo/solaris/jni/Poller/PollingServer.java
+++ /dev/null
@@ -1,265 +0,0 @@
-/*
- * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-
-import java.io.*;
-import java.net.*;
-import java.lang.Byte;
-
-/**
- * Simple Java "server" using the Poller class
- * to multiplex on incoming connections. Note
- * that handoff of events, via linked Q is not
- * actually be a performance booster here, since
- * the processing of events is cheaper than
- * the overhead in scheduling/executing them.
- * Although this demo does allow for concurrency
- * in handling connections, it uses a rather
- * primitive "gang scheduling" policy to keep
- * the code simpler.
- */
-
-public class PollingServer
-{
- public final static int MAXCONN = 10000;
- public final static int PORTNUM = 4444;
- public final static int BYTESPEROP = 10;
-
- /**
- * This synchronization object protects access to certain
- * data (bytesRead,eventsToProcess) by concurrent Consumer threads.
- */
- private final static Object eventSync = new Object();
-
- private static InputStream[] instr = new InputStream[MAXCONN];
- private static int[] mapping = new int[65535];
- private static LinkedQueue linkedQ = new LinkedQueue();
- private static int bytesRead = 0;
- private static int bytesToRead;
- private static int eventsToProcess=0;
-
- public PollingServer(int concurrency) {
- Socket[] sockArr = new Socket[MAXCONN];
- long timestart, timestop;
- short[] revents = new short[MAXCONN];
- int[] fds = new int[MAXCONN];
- int bytes;
- Poller Mux;
- int serverFd;
- int totalConn=0;
- int connects=0;
-
- System.out.println ("Serv: Initializing port " + PORTNUM);
- try {
-
- ServerSocket skMain = new ServerSocket (PORTNUM);
- /*
- * Create the Poller object Mux, allow for up to MAXCONN
- * sockets/filedescriptors to be polled.
- */
- Mux = new Poller(MAXCONN);
- serverFd = Mux.add(skMain, Poller.POLLIN);
-
- Socket ctrlSock = skMain.accept();
-
- BufferedReader ctrlReader =
- new BufferedReader(new InputStreamReader(ctrlSock.getInputStream()));
- String ctrlString = ctrlReader.readLine();
- bytesToRead = Integer.valueOf(ctrlString).intValue();
- ctrlString = ctrlReader.readLine();
- totalConn = Integer.valueOf(ctrlString).intValue();
-
- System.out.println("Receiving " + bytesToRead + " bytes from " +
- totalConn + " client connections");
-
- timestart = System.currentTimeMillis();
-
- /*
- * Start the consumer threads to read data.
- */
- for (int consumerThread = 0;
- consumerThread < concurrency; consumerThread++ ) {
- new Consumer(consumerThread).start();
- }
-
- /*
- * Take connections, read Data
- */
- int numEvents=0;
-
- while ( bytesRead < bytesToRead ) {
-
- int loopWaits=0;
- while (eventsToProcess > 0) {
- synchronized (eventSync) {
- loopWaits++;
- if (eventsToProcess <= 0) break;
- try { eventSync.wait(); } catch (Exception e) {e.printStackTrace();};
- }
- }
- if (loopWaits > 1)
- System.out.println("Done waiting...loops = " + loopWaits +
- " events " + numEvents +
- " bytes read : " + bytesRead );
-
- if (bytesRead >= bytesToRead) break; // may be done!
-
- /*
- * Wait for events
- */
- numEvents = Mux.waitMultiple(100, fds, revents);
- synchronized (eventSync) {
- eventsToProcess = numEvents;
- }
- /*
- * Process all the events we got from Mux.waitMultiple
- */
- int cnt = 0;
- while ( (cnt < numEvents) && (bytesRead < bytesToRead) ) {
- int fd = fds[cnt];
-
- if (revents[cnt] == Poller.POLLIN) {
- if (fd == serverFd) {
- /*
- * New connection coming in on the ServerSocket
- * Add the socket to the Mux, keep track of mapping
- * the fdval returned by Mux.add to the connection.
- */
- sockArr[connects] = skMain.accept();
- instr[connects] = sockArr[connects].getInputStream();
- int fdval = Mux.add(sockArr[connects], Poller.POLLIN);
- mapping[fdval] = connects;
- synchronized(eventSync) {
- eventsToProcess--; // just processed this one!
- }
- connects++;
- } else {
- /*
- * We've got data from this client connection.
- * Put it on the queue for the consumer threads to process.
- */
- linkedQ.put(new Integer(fd));
- }
- } else {
- System.out.println("Got revents[" + cnt + "] == " + revents[cnt]);
- }
- cnt++;
- }
- }
- timestop = System.currentTimeMillis();
- System.out.println("Time for all reads (" + totalConn +
- " sockets) : " + (timestop-timestart));
-
- // Tell the client it can now go away
- byte[] buff = new byte[BYTESPEROP];
- ctrlSock.getOutputStream().write(buff,0,BYTESPEROP);
-
- // Tell the cunsumer threads they can exit.
- for (int cThread = 0; cThread < concurrency; cThread++ ) {
- linkedQ.put(new Integer(-1));
- }
- } catch (Exception exc) { exc.printStackTrace(); }
- }
-
- /*
- * main ... just check if a concurrency was specified
- */
- public static void main (String args[])
- {
- int concurrency;
-
- if (args.length == 1)
- concurrency = java.lang.Integer.valueOf(args[0]).intValue();
- else
- concurrency = Poller.getNumCPUs() + 1;
- PollingServer server = new PollingServer(concurrency);
- }
-
- /*
- * This class is for handling the Client data.
- * The PollingServer spawns off a number of these based upon
- * the number of CPUs (or concurrency argument).
- * Each just loops grabbing events off the queue and
- * processing them.
- */
- class Consumer extends Thread {
- private int threadNumber;
- public Consumer(int i) { threadNumber = i; }
-
- public void run() {
- byte[] buff = new byte[BYTESPEROP];
- int bytes = 0;
-
- InputStream instream;
- while (bytesRead < bytesToRead) {
- try {
- Integer Fd = (Integer) linkedQ.take();
- int fd = Fd.intValue();
- if (fd == -1) break; /* got told we could exit */
-
- /*
- * We have to map the fd value returned from waitMultiple
- * to the actual input stream associated with that fd.
- * Take a look at how the Mux.add() was done to see how
- * we stored that.
- */
- int map = mapping[fd];
- instream = instr[map];
- bytes = instream.read(buff,0,BYTESPEROP);
- } catch (Exception e) { System.out.println(e.toString()); }
-
- if (bytes > 0) {
- /*
- * Any real server would do some synchronized and some
- * unsynchronized work on behalf of the client, and
- * most likely send some data back...but this is a
- * gross oversimplification.
- */
- synchronized(eventSync) {
- bytesRead += bytes;
- eventsToProcess--;
- if (eventsToProcess <= 0) {
- eventSync.notify();
- }
- }
- }
- }
- }
- }
-}
diff --git a/jdk/src/demo/solaris/jni/Poller/README.txt b/jdk/src/demo/solaris/jni/Poller/README.txt
deleted file mode 100644
index d665c221e8b..00000000000
--- a/jdk/src/demo/solaris/jni/Poller/README.txt
+++ /dev/null
@@ -1,174 +0,0 @@
-README.txt
-
-
-This Poller class demonstrates access to poll(2) functionality in Java.
-
-Requires Solaris production (native threads) JDK 1.2 or later, currently
-the C code compiles only on Solaris (SPARC and Intel).
-
-Poller.java is the class, Poller.c is the supporting JNI code.
-
-PollingServer.java is a sample application which uses the Poller class
-to multiplex sockets.
-
-SimpleServer.java is the functional equivalent that does not multiplex
-but uses a single thread to handle each client connection.
-
-Client.java is a sample application to drive against either server.
-
-To build the Poller class and client/server demo :
- javac PollingServer.java Client.java
- javah Poller
- cc -G -o libpoller.so -I ${JAVA_HOME}/include -I ${JAVA_HOME}/include/solaris\
- Poller.c
-
-You will need to set the environment variable LD_LIBRARY_PATH to search
-the directory containing libpoller.so.
-
-To use client/server, bump up your fd limit to handle the connections you
-want (need root access to go beyond 1024). For info on changing your file
-descriptor limit, type "man limit". If you are using Solaris 2.6
-or later, a regression in loopback read() performance may hit you at low
-numbers of connections, so run the client on another machine.
-
-BASICs of Poller class usage :
- run "javadoc Poller" or see Poller.java for more details.
-
-{
- Poller Mux = new Poller(65535); // allow it to contain 64K IO objects
-
- int fd1 = Mux.add(socket1, Poller.POLLIN);
- ...
- int fdN = Mux.add(socketN, Poller.POLLIN);
-
- int[] fds = new int[100];
- short[] revents = new revents[100];
-
- int numEvents = Mux.waitMultiple(100, fds, revents, timeout);
-
- for (int i = 0; i < numEvents; i++) {
- /*
- * Probably need more sophisticated mapping scheme than this!
- */
- if (fds[i] == fd1) {
- System.out.println("Got data on socket1");
- socket1.getInputStream().read(byteArray);
- // Do something based upon state of fd1 connection
- }
- ...
- }
-}
-
-Poller class implementation notes :
-
- Currently all add(),remove(),isMember(), and waitMultiple() methods
-are synchronized for each Poller object. If one thread is blocked in
-pObj.waitMultiple(), another thread calling pObj.add(fd) will block
-until waitMultiple() returns. There is no provided mechanism to
-interrupt waitMultiple(), as one might expect a ServerSocket to be in
-the list waited on (see PollingServer.java).
-
- One might also need to interrupt waitMultiple() to remove()
-fds/sockets, in which case one could create a Pipe or loopback localhost
-connection (at the level of PollingServer) and use a write() to that
-connection to interrupt. Or, better, one could queue up deletions
-until the next return of waitMultiple(). Or one could implement an
-interrupt mechanism in the JNI C code using a pipe(), and expose that
-at the Java level.
-
- If frequent deletions/re-additions of socks/fds is to be done with
-very large sets of monitored fds, the Solaris 7 kernel cache will
-likely perform poorly without some tuning. One could differentiate
-between deleted (no longer cared for) fds/socks and those that are
-merely being disabled while data is processed on their behalf. In
-that case, re-enabling a disabled fd/sock could put it in it's
-original position in the poll array, thereby increasing the kernel
-cache performance. This would best be done in Poller.c. Of course
-this is not necessary for optimal /dev/poll performance.
-
- Caution...the next paragraph gets a little technical for the
-benefit of those who already understand poll()ing fairly well. Others
-may choose to skip over it to read notes on the demo server.
-
- An optimal solution for frequent enabling/disabling of socks/fds
-could involve a separately synchronized structure of "async"
-operations. Using a simple array (0..64k) containing the action
-(ADD,ENABLE,DISABLE, NONE), the events, and the index into the poll
-array, and having nativeWait() wake up in the poll() call periodically
-to process these async operations, I was able to speed up performance
-of the PollingServer by a factor of 2x at 8000 connections. Of course
-much of that gain was from the fact that I could (with the advent of
-an asyncAdd() method) move the accept() loop into a separate thread
-from the main poll() loop, and avoid the overhead of calling poll()
-with up to 7999 fds just for an accept. In implementing the async
-Disable/Enable, a further large optimization was to auto-disable fds
-with events available (before return from nativeWait()), so I could
-just call asyncEnable(fd) after processing (read()ing) the available
-data. This removed the need for inefficient gang-scheduling the
-attached PollingServer uses. In order to separately synchronize the
-async structure, yet still be able to operate on it from within
-nativeWait(), synchronization had to be done at the C level here. Due
-to the new complexities this introduced, as well as the fact that it
-was tuned specifically for Solaris 7 poll() improvements (not
-/dev/poll), this extra logic was left out of this demo.
-
-
-Client/Server Demo Notes :
-
- Do not run the sample client/server with high numbers of connections
-unless you have a lot of free memory on your machine, as it can saturate
-CPU and lock you out of CDE just by its very resource intensive nature
-(much more so the SimpleServer than PollingServer).
-
- Different OS versions will behave very differently as far as poll()
-performance (or /dev/poll existence) but, generally, real world applications
-"hit the wall" much earlier when a separate thread is used to handle
-each client connection. Issues of thread synchronization and locking
-granularity become performance killers. There is some overhead associated
-with multiplexing, such as keeping track of the state of each connection; as
-the number of connections gets very large, however, this overhead is more
-than made up for by the reduced synchronization overhead.
-
- As an example, running the servers on a Solaris 7 PC (Pentium II-350 x
-2 CPUS) with 1 GB RAM, and the client on an Ultra-2, I got the following
-times (shorter is better) :
-
- 1000 connections :
-
-PollingServer took 11 seconds
-SimpleServer took 12 seconds
-
- 4000 connections :
-
-PollingServer took 20 seconds
-SimpleServer took 37 seconds
-
- 8000 connections :
-
-PollingServer took 39 seconds
-SimpleServer took 1:48 seconds
-
- This demo is not, however, meant to be considered some form of proof
-that multiplexing with the Poller class will gain you performance; this
-code is actually very heavily biased towards the non-polling server as
-very little synchronization is done, and most of the overhead is in the
-kernel IO for both servers. Use of multiplexing may be helpful in
-many, but certainly not all, circumstances.
-
- Benchmarking a major Java server application which can run
-in a single-thread-per-client mode or using the new Poller class showed
-Poller provided a 253% improvement in throughput at a moderate load, as
-well as a 300% improvement in peak capacity. It also yielded a 21%
-smaller memory footprint at the lower load level.
-
- Finally, there is code in Poller.c to take advantage of /dev/poll
-on OS versions that have that device; however, DEVPOLL must be defined
-in compiling Poller.c (and it must be compiled on a machine with
-/usr/include/sys/devpoll.h) to use it. Code compiled with DEVPOLL
-turned on will work on machines that don't have kernel support for
-the device, as it will fall back to using poll() in those cases.
-Currently /dev/poll does not correctly return an error if you attempt
-to remove() an object that was never added, but this should be fixed
-in an upcoming /dev/poll patch. The binary as shipped is not built with
-/dev/poll support as our build machine does not have devpoll.h.
-
diff --git a/jdk/src/demo/solaris/jni/Poller/SimpleServer.java b/jdk/src/demo/solaris/jni/Poller/SimpleServer.java
deleted file mode 100644
index 6a099c67071..00000000000
--- a/jdk/src/demo/solaris/jni/Poller/SimpleServer.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-
-import java.io.*;
-import java.net.*;
-import java.lang.Byte;
-
-/**
- * Simple Java "server" using a single thread to handle each connection.
- */
-
-public class SimpleServer
-{
- private final static int BYTESPEROP= PollingServer.BYTESPEROP;
- private final static int PORTNUM = PollingServer.PORTNUM;
- private final static int MAXCONN = PollingServer.MAXCONN;
-
- /*
- * This synchronization object protects access to certain
- * data (bytesRead,eventsToProcess) by concurrent Consumer threads.
- */
- private final static Object eventSync = new Object();
-
- private static InputStream[] instr = new InputStream[MAXCONN];
- private static int bytesRead;
- private static int bytesToRead;
-
- public SimpleServer() {
- Socket[] sockArr = new Socket[MAXCONN];
- long timestart, timestop;
- int bytes;
- int totalConn=0;
-
-
- System.out.println ("Serv: Initializing port " + PORTNUM);
- try {
-
- ServerSocket skMain = new ServerSocket (PORTNUM);
-
- bytesRead = 0;
- Socket ctrlSock = skMain.accept();
-
- BufferedReader ctrlReader =
- new BufferedReader(new InputStreamReader(ctrlSock.getInputStream()));
- String ctrlString = ctrlReader.readLine();
- bytesToRead = Integer.valueOf(ctrlString).intValue();
- ctrlString = ctrlReader.readLine();
- totalConn = Integer.valueOf(ctrlString).intValue();
-
- System.out.println("Receiving " + bytesToRead + " bytes from " +
- totalConn + " client connections");
-
- timestart = System.currentTimeMillis();
-
- /*
- * Take connections, spawn off connection handling threads
- */
- ConnHandler[] connHA = new ConnHandler[MAXCONN];
- int conn = 0;
- while ( conn < totalConn ) {
- Socket sock = skMain.accept();
- connHA[conn] = new ConnHandler(sock.getInputStream());
- connHA[conn].start();
- conn++;
- }
-
- while ( bytesRead < bytesToRead ) {
- java.lang.Thread.sleep(500);
- }
- timestop = System.currentTimeMillis();
- System.out.println("Time for all reads (" + totalConn +
- " sockets) : " + (timestop-timestart));
- // Tell the client it can now go away
- byte[] buff = new byte[BYTESPEROP];
- ctrlSock.getOutputStream().write(buff,0,BYTESPEROP);
- } catch (Exception exc) { exc.printStackTrace(); }
- }
-
- /*
- * main ... just create invoke the SimpleServer constructor.
- */
- public static void main (String args[])
- {
- SimpleServer server = new SimpleServer();
- }
-
- /*
- * Connection Handler inner class...one of these per client connection.
- */
- class ConnHandler extends Thread {
- private InputStream instr;
- public ConnHandler(InputStream inputStr) { instr = inputStr; }
-
- public void run() {
- try {
- int bytes;
- byte[] buff = new byte[BYTESPEROP];
-
- while ( bytesRead < bytesToRead ) {
- bytes = instr.read (buff, 0, BYTESPEROP);
- if (bytes > 0 ) {
- synchronized(eventSync) {
- bytesRead += bytes;
- }
- /*
- * Any real server would do some synchronized and some
- * unsynchronized work on behalf of the client, and
- * most likely send some data back...but this is a
- * gross oversimplification.
- */
- }
- else {
- if (bytesRead < bytesToRead)
- System.out.println("instr.read returned : " + bytes);
- }
- }
- }
- catch (Exception e) {e.printStackTrace();}
- }
- }
-}
diff --git a/jdk/src/sample/share/README b/jdk/src/sample/share/README
deleted file mode 100644
index ae56b64d728..00000000000
--- a/jdk/src/sample/share/README
+++ /dev/null
@@ -1,6 +0,0 @@
-The source code provided with samples and demos for the JDK is meant
-to illustrate the usage of a given feature or technique and has been
-deliberately simplified. Additional steps required for a
-production-quality application, such as security checks, input
-validation, and proper error handling, might not be present in the
-sample code.
diff --git a/jdk/src/sample/share/annotations/DependencyChecker/PluginChecker/src/checker/Device.java b/jdk/src/sample/share/annotations/DependencyChecker/PluginChecker/src/checker/Device.java
deleted file mode 100644
index 2a5c6d3c89e..00000000000
--- a/jdk/src/sample/share/annotations/DependencyChecker/PluginChecker/src/checker/Device.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-package checker;
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-import java.util.Collections;
-import java.util.EnumMap;
-import java.util.Map;
-
-/**
- * Represents the device configuration. The values are loaded from an XML file by JAXB.
- */
-@XmlRootElement
-public class Device {
-
- @XmlElement()
- private MapRepeating Annotations Demo
-
-
-
Dependency checker.
-
- javac -cp "PluginChecker.jar" -processor checker.PluginChecker -Adevice=Kettle.xml -proc:only <source
- files>
-
- PluginChecker.jar - path to jar file that contains PluginChecker annotation processor
- class.
- Kettle.xml - path to device descriptor Kettle.xml
- <source files> - source files in Plugins/src
-
-
-
- Validator.
-
-
-
-
-
- Introduction
-
-
-
- Note: This example was developed using NetBeans 5.0 IDE. The instructions
- given in this document to build, run, and test the example assume that
- you have at your disposal:
-
-
-
- (JUnit is only needed to run the example's unit tests).
-
In that case, you will need to update the nbjdk.home variable
- in the copied build.properties
- file located at the root of the copied project directory.
- Please make sure that this variable points to the JDK 6 home directory.
-
-
- Generating the Java Documentation
-
-
-
build.xml
- file is located) run the following command:
- ant javadoc
- Build
- menu.
- Overview of the scandir Example
-
-
-
-
-
A
- DirectoryScannerMXBean is an MBean that scans a
- file system starting at a given root directory, and then looks
- for files that match the given criteria. When such a file is
- found, the DirectoryScannerMXBean takes the
- action for which it was configured: emit a notification,
- and/or log a record for this file,
- and/or delete that file. The code that would actually
- delete the file is commented out - so that nothing valuable is
- lost if the example is run by mistake on the wrong set of
- directories.
DirectoryScannerMXBeans are
- created by the ScanManagerMXBean - see next item on the list, from its
- configuration.
-
The ScanManagerMXBean lets you start, stop, and
- schedule directory scans. The
- ScanManagerMXBean is a singleton
- MBean: there can be at most one instance of such
- an MBean registered in a given MBeanServer.
- ScanManagerMXBean to apply the
- configuration again.
- The ScanDirConfigMXBean is created by the
- ScanManagerMXBean, when the
- ScanManagerMXBean is registered.
- It is also possible to create an alternate
- ScanDirConfigMXBean, and to switch the
- ScanDirConfigMXBean to use one or the other
- configuration.
-
An example of XML configuration file is given
- here. Although you could edit such a file by
- hand, it is easier to do it programmatically (or
- with JConsole) through
- the ScanDirConfigMXBean interface.
-
Directory Scanners can be configured to log a
- ResultRecord whenever they take action upon a file that
- matches their criteria. The ResultLogManagerMXBean is
- responsible for logging these result records.
- The ResultLogManagerMXBean can be configured to log
- such records to a flat file, or into a log held in memory, or
- both. Both logs (file and memory) can be configured with a
- maximum capacity.
-
When the maximum capacity of the memory
- log is reached, its first entry (i.e. its oldest entry) is
- removed to make place for the latest one.
-
When the maximum
- capacity of the file log is reached, the file is
- renamed by appending a tilde '~' to its name and a
- new result log is created.
-
The ResultLogManagerMXBean
- will let you interactively clear these result logs, change their
- capacity, and decide where (memory or file) to log.
- The memory log is useful in that its content can be interactively
- returned by the ResultLogManagerMXBean, while
- the file log doesn't have this facility.
- The result logs are intended to be used by e.g. an offline
- program that would take some actions on the files that
- matched the scan criteria:
-
The scandir application
- could be configured to only produce logs (i.e. takes no
- action but logging the matching files), and the real
- action could be performed by another program or module (e.g. mail the result log to the engineer who
- maintains the lab, or parse that log and delete all the
- files listed there, or parse the log and prepare and send
- a single mail to each owner of matching files, containing
- the list of files they should consider deleting).
- The ResultLogManagerMXBean is a singleton
- MBean created by the ScanManagerMXBean
- which reads and writes its configuration from the
- ScanDirConfigMXBean.
- main() method is
- provided in the ScanDirAgent class. The main() simply registers
- a ScanManagerMXBean in the platform MBeanServer, and
- then waits for someone to call close() on the
- ScanManagerMXBean.
- ScanManagerMXBean is registered, it
- will create a default ScanDirConfigMXBean bound
- to a default XML config file.
-
-
- scandir.config.file is
- defined, the default application file will be the
- file pointed to by this property. If that file
- doesn't exist, it will be created when
- ScanDirConfigMXBean.save() is
- invoked.
- jmx-scandir.xml,
- located in the user's directory (as defined by
- the System property user.home).
- If that file doesn't exists, it will be created when
- ScanDirConfigMXBean.save() is
- invoked.
- -Djava.util.logging.config.file=logging.properties
- -Dscandir.config.file=src/etc/testconfig.xml
- With ScanDirAgent defined as the project's
- main class. Hence when you invoke from the NetBeans IDE
- Run Project on the jmx-scandir project,
- or Run file on the ScanDirAgent, the
- application starts with the test configuration provided in
- src/etc/testconfig.xml
- API Documentation and Sources
-
-
- dist/javadoc/index.html.src subdirectory.Patterns, Best Practices, and Common Pitfalls
-
-
- MBeans or MXBeans?
-
-
- WombatMBean interface into WombatMXBean.
-
- DirectoryScannerMXBean and points
- towards a ScanDirConfigMXBean.
- Hint: In order to simplify the task of coding a
- JMX programmatic client, we recommend that getters, setters, and
- operations defined in MBean and MXBean interfaces throw
-
- IOException. Proxy objects will then be able
- to rethrow directly any IOException received from
- their underlying MBean Server connection, without wrapping
- them into UndeclaredThrowableExceptions.
- Since the life cycle of the proxy object is not directly tied to
- the life cycle of the MBean it proxies, you may also want to
- have all methods in the MBean or MXBean interface throw
- InstanceNotFoundException or more generally
- JMException.
- MBean Names - aka ObjectNames
-
-
- ObjectName. An ObjectName is
- composed of a domain, followed by a colon ':',
- followed by a comma-separated list of key=value
- pairs.
- The ordering of the key=value pairs is not
- important, but ObjectNames are case sensitive
- (both keys and values are case sensitive) and white space
- is not ignored.
- A common pitfall for JMX beginners is to inadvertently
- insert white space after commas into an ObjectName,
- and expect that two ObjectNames which differ only by such white
- space will be considered identical. This is not the
- case.
- As an example, the ObjectName 'D:k1=v1, k2=v2, k3=v3' has
- three keys, which are 'k1', ' k2',
- and ' k3': beware
- of the space in the name of the second and third
- keys!
- It is therefore a different ObjectName from
- 'D:k1=v1,k2=v2,k3=v3' (the keys are now
- 'k1', 'k2', and
- 'k3'), but the same ObjectName as
- 'D: k2=v2, k3=v3,k1=v1', and yet different
- from 'D:k2=v2, k3=v3, k1=v1'!
-
-
- type=
- key property. This property is different for every
- object type in our domain.
- name= key.
- type=.
- The ObjectNames of the ScanManagerMXBean and ResultLogManagerMXBean, which are both singleton MBeans, are
- composed in this way.
- type=: the name= key.
- In this example, a key property list of the form
- type=X,name=Y is always enough to uniquely name
- an MBean. Tools like jconsole are usually aware
- of the semantics of the type= key and
- name= key, and are therefore able to
- display this form of name in a way that
- is easier to read than other name forms.
- makeSingletonName and
- makeMBeanName methods.
- Inter MBean Navigation
-
-
- Prior to Java 6, there were basically three possible
- choices:
-
-
- The obvious limitation of this solution is that
- it only allows to model one such relation (an
- MBean has only one name) and the relation must
- be fixed - it cannot change during the life of
- the MBean since the name of an MBean cannot
- change.
- This scheme is therefore mostly used when
- the application MBeans are modeling objects
- which are conceptually contained within
- each other in a tree-like structure.
-
For instance, most MBean names defined by
- J2EE Management (JSR 77) follow
- this scheme.
- ObjectName or
- ObjectName[] values. The ObjectNames
- point to the MBeans which are related to that
- object. For instance , GlassFish
- defines MBeans which also use this pattern.
-
For instance the
- ScanManagerMXBean/DirectoryScannerMXBean
- relationship and the
- ScanManagerMXBean/ScanDirConfigMXBean
- relationships are implemented in this way.
-
- public Map<String,DirectoryScannerMXBean> getDirectoryScanners();
-
- makes it immediately obvious that the MBeans to which we point are
- DirectoryScannerMXBeans. It would have been much less obvious in prior
- versions of Java SE, were the returned type would have had to be
- Map<String,ObjectName>, or
- even worse just Map.
- getDirectoryScanners will cause the
- MBean to be invoked on the remote server side.
- getDirectoryScanners were
- defined as:
-
- public Map<String,DirectoryScannerConfig> getDirectoryScanners();
-
- then invoking a method on one of the returned objects
- would have absolutely no effect on the remote
- server side - because the returned objects in this
- case would simply be a bunch of serialized data objects.
- The MBeanRegistration interface, or how an MBean can
- know or provide its own name
-
-
MBeanRegistration
- interface.
- MBeanRegistration interface is a callback
- interface which defines pre and post registration and
- unregistration callbacks.
- createMBean) or registered
- (with registerMBean) in an MBeanServer,
- the MBeanServer will call the preRegister
- and postRegister method implemented by
- the MBean. The preRegister method
- has an MBeanServer and ObjectName
- parameter, which are passed by the MBeanServer to the
- MBean. The MBean can store the reference it is being passed
- in a private instance variable for later use.
- MBeanRegistration interface. The table
- below show how our MBeans use this interface to control
- their own names, make sanity checks, perform
- initialization steps or cleanup actions.
-
-
-
-
-
-
-
- MBean Requirement
- callback
- use case example
-
-
- get a reference to the MBeanServer
-
- preRegisterThe ScanManagerMXBean needs a reference
- to the MBeanServer in order to create and
- register other MBeans, such as the
- ResultLogManagerMXBean, and the
- DirectoryScannerMXBeans.
-
-
-
- reject registration if conditions are
- not met.
-
-
- preRegisterThe ScanManagerMXBean will throw
- an IllegalArgumentException in
- preRegister
- if the ObjectName it is being passed is
- illegal. Throwing an exception in
- preRegister makes the registration fail.
-
-
- get my client-assigned MBean name
-
- preRegisterThe ScanDirConfigMXBean propagates the
- value of the
- name= property of
- the ObjectName it is given into its
- ScanManagerConfig bean.
-
-
- provide my own default ObjectName if none
- was given to the MBeanServer
-
-
- preRegisterThe name that is returned by
- preRegister
- is the ObjectName with which the MBean will be
- eventually registered.
- The ScanDirConfigMXBean is able to suggest
- a value for its own ObjectName if none was
- provided. Similarly, the ScanManagerMXBean
- always returns its singleton ObjectName
- defined by ScanManagerMXBean.SCAN_MANAGER_NAME.
-
-
- perform initialization steps
-
- preRegisterThe ScanDirConfigMXBean uses
- preRegister
- to initialize its internal ScanManagerConfig bean.
-
-
- perform initialization steps, once it is
- known that the registration was successful.
-
-
- postRegisterThe
- postRegister method
- can be used to implement
- initialization steps that need to be done once it
- is known that the registration was successful, or to
- undo any action performed by preRegister once it
- is known that registration was not successful.
- The postRegister method has a Boolean parameter
- which tells the MBean whether it was or wasn't
- successfully registered in the MBeanServer.
- The ScanManagerMXBean uses postRegister to create
- and register other MBeans, such as the
- ResultLogManagerMXBean and the default
- ScanDirConfigMXBean.
- Note that postRegister is not expected to throw any
- exception. If an exception needs to be thrown, it should
- be thrown in preRegister.
-
-
- check whether the MBean can be deregistered
-
- preDeregisterThe ScanManagerMXBean uses this method to verify
- that its state allows it to be deregistered.
- In particular, it will refuse to be deregistered
- if it is in the RUNNING or SCHEDULED state.
- If
- preDeregister throws an exception, the unregisterMBean
- call will fail and the MBean will remain registered in
- the MBeanServer.
- Take particular care when implementing business logic
- in this method: if the logic you implement has an
- unfortunate bug which makes it always throw an
- exception, you will never be able to unregister
- that MBean.
-
-
- clean up resources, refusing to be deregistered if
- it fails
-
-
- preDeregisterThe ScanManagerMXBean uses this method to unregister
- all the other MBeans it has created and registered in the
- MBeanServer. This includes the ResultLogManagerMXBean, the
- ScanDirConfigMXBeans it has created, and the
- DirectoryScannerMXBeans it has created when
- applying its configuration.
-
-
-
-
- clean up resources which need to be released in
- a best-effort way, when it is known that the MBean is no
- longer registered.
-
-
- postDeregister
- postDeregister is only called if the MBean was succesfully
- unregistered.
- The ScanManagerMXBean uses this method to cancel
- its internal java.util.Timer.
- The Singleton MBean Pattern
-
-
-
- A singleton MBean usually has a well-known name,
- which can be defined as a constant. In that case,
- clients no longer need to call new ObjectName(...)
- and catch the declared MalformedObjectNameException.
- ScanManagerMXBean and the
- ResultLogManagerMXBean. But in fact,
- the only real singleton MBean is the
- ScanManagerMXBean. The
- ResultLogManagerMXBean just happens to
- be a singleton MBean because it has a 1-1 relationship
- with the ScanManagerMXBean.
- ScanManagerMXBean implements the
- singleton MBean pattern in this way:
-
-
- ScanManagerMXBean name has a single
- key property: type=ScanManagerMXBean.SCAN_MANAGER_NAME in the ScanManager classScanManagerMXBean enforces its status of
- singleton MBean. It will refuse to be registered
- with a name other than
- the SCAN_MANAGER_NAME. You can therefore depend on
- the fact that the ScanManagerMXBean will always
- be registered with its singleton SCAN_MANAGER_NAME
- (see preRegister)
- ScanManagerMXBean: if you pass null,
- then the ScanManager will be registered with
- its singleton SCAN_MANAGER_NAME
- (see preRegister).
- ScanManager class has a no-arg static
- register method that will register
- the singleton instance in the Platform MBeanServer.
- This static register method returns
- a proxy to the registered singleton.
- ScanManager class has also a static
- register method that will create
- a singleton instance in a (possibly remote)
- MBeanServerConnection - using
- createMBean.
- This static register method
- also returns a proxy to the registered singleton.
- ResultLogManagerMXBean
- has a much more relaxed implementation of the pattern:
-
It simply provides its own singleton name if it is
- registered with a null ObjectName, but will not enforce
- the use of that name.
- ScanManager.makeSingletonName
- method, which implements the pattern for ObjectNames suggested
- in the JMX Best Practices.
- Managing the Life Cycle of dependent MBeans
-
-
-
-
- ScanManagerMXBean will then
- in turn register any other MBean that the
- application might need:
-
-
- ResultLogManagerMXBean
- ScanDirConfigMXBean
- which loads the initial configuration
- DirectoryScannerMXBeans as
- needed when the configuration is applied
- ScanDirConfigMXBean, to
- which you can later switch in order
- to apply a new alternate configuration.
- ScanManagerMXBean will unregister
- any DirectoryScannerMXBeans it has
- previously registered, and will re-create
- brand new DirectoryScannerMXBeans
- from the applied configuration.
- ScanManagerMXBean,
- it does all the cleanup for you, by unregistering
- all the MBeans that it has created during the
- course of the application.
- ScanManagerMXBean makes use of its
- MBeanRegistration interface in order
- to register the other MBeans it needs (see the
- ScanManager.postRegister method) and to unregister
- every MBean it has created (see the ScanManager.preDeregister
- method).
- ScanManagerMXBean
- will only allow itself to be deregistered if it can be
- closed - that is if there's no other action in
- progress.
- This is to make sure that the deregistration of
- dependent MBeans will work smoothly.
-
- The deregistration of related MBeans will happen
- in the ScanManager.preDeregister
- method.
-
- If one of these MBeans could not be deregistered,
- then the ScanManagerMXBean will throw
- an exception, refusing to be deregistered.
-
This leaves you a chance to try to deregister it
- again later. Since the ScanManagerMXBean
- has switched its state to CLOSED before starting
- to unregister its dependent MBeans, it will refuse
- any further actions, ensuring that e.g. nobody
- can try to start it or schedule it while it
- is in that partially-deregistered state.
- ScanManagerMXBean) does
- the trick.
- Emitting Notifications
-
-
-
- NotificationEmitter.
- The NotificationEmitter interface defines methods
- that the MBeanServer will call on the MBean in order
- to register NotificationListeners with the MBean.
- NotificationEmitter.
- In that specific case, the listener may even be registered
- with the MBean before any client has actually subscribed
- for notifications from that particular MBean.
- NotificationEmitter would not
- be trivial to implement from scratch. Fortunately
- the JMX API defines a helper class, called
- NotificationBroadcasterSupport, which
- provides an implementation for these methods.
- NotificationEmitter, of which only two
- are recommended.
- Extending NotificationBroadcasterSupport
-
-
- NotificationEmitter:
- NotificationBroadcasterSupport,
- then override its getNotificationInfo method
- which returns the MBeanNotificationInfo[] array
- that should be included in your MBean's MBeanInfo
- and that's it.
-
You just need to call the sendNotification method
- inherited from NotificationBroadcasterSupport whenever
- your MBean needs to send a notification.
- NotificationBroadcasterSupport in order
- to send notifications.
- The Delegation Pattern: delegating to a
- NotificationBroadcasterSupport delegate
-
-
-
- NotificationBroadcasterSupport
- object may be preferred to extending
- NotificationBroadcasterSupport.
- NotificationBroadcasterSupport
- might not be an option.
- public void sendNotification(Notification notification)
- method appear in the Javadoc of the concrete class of your
- MBean, you may want to consider using the delegation
- pattern instead of extending
- NotificationBroadcasterSupport
- NotificationBroadcasterSupport.
- In the end, choosing between one or the other method
- is more a question of taste, although the delegation
- pattern could be considered more flexible since it
- doesn't require extending any given superclass.
- NotificationBroadcasterSupport.
- Implementing NotificationEmitter from scratch
-
-
-
- NotificationEmitter from scratch. This is highly
- discouraged since that logic is not trivial, and
- already provided by
- NotificationBroadcasterSupport anyway.
- Beware of Synchronization Locks
-
-
-
JMXConnector (like the
- JMXRMIConnector)
- or through a direct reference to the MBeanServer
- (by calling
- MBeanServer.addNotificationListener).
- sendNotification.ScanManager class. The ScanManager
- has an internal private queue of pending notifications.
- When a notification needs to be sent (e.g. because the
- ScanManager state is being switched), the notification
- is simply prepared and put into the pending notification
- queue.
- The notification queue is then processed later on,
- at the end of the method, when the processing is finally
- completed and all the locks have been released.
-
At this point the notification queue might already
- have been emptied by another thread - in which case
- the pending notifications will have already been
- removed from the queue. Which thread actually gets
- to send the notifications is of no importance. The
- important point is that all the locks detained by
- your MBean code in that thread were released before
- the notification was sent.
- ScanManager class
- ensures this by:
-
-
- sendNotification
- in its private sendQueuedNotifications
- method.
- sendQueuedNotifications
- when all locks have been released.
- sendQueuedNotifications from within
- a synchronized block.Don't subclass Notification
-
-
-
- AttributeChangeNotification to notify
- changes in their State attribute.
- Notification
- class directly in order to notify whenever
- it finds a matching file.
-
In that case, we simply use the base
- Notification
- class with a new
- com.sun.jmx.examples.scandir.filematch
- type.
- Notification class.
- AttributeChangeNotification class
- to notify about their state change, whereas the
- ScanDirConfigMXBean uses the base
- Notification class.
-
-
- ScanManagerMXBean
- and DirectoryScannerMXBean, the
- notification which is emitted is more about a
- state transition, from one state to another.
- For instance, going from RUNNING
- to STOPPED, or from
- SCHEDULED to STOPPED.
-
In that case, the
- AttributeChangeNotification was
- more appropriate because it made it possible
- to send the previous and the new value of the
- state attribute, thus reflecting the whole
- state transition.
- ScanDirConfigMXBean
- however, what is of interest is the state in
- which the MBean has arrived. Using the base
- Notification class with three different
- notification type strings -
- com.sun.jmx.examples.scandir.config.loaded,
- com.sun.jmx.examples.scandir.config.modified,
- and
- com.sun.jmx.examples.scandir.config.saved -
- was therefore closer to what we wanted to model.
- Configuration MBeans
-
-
- ScanDirConfigMXBean will let you interactively
- modify, save, or load the application configuration. The modifications
- will not be taken into account until it is applied, by invoking
- applyConfiguration on the ScanManagerMXBean.
- It is also possible to create many configurations, by creating as
- many ScanDirConfigMXBeans, and then to choose and apply
- one of these configurations by calling
- ScanManagerMXBean.setConfigurationMBean and then
- ScanManagerMXBean.applyConfiguration.
- ScanDirConfigMXBean instead of being scattered
- throughout all the MBeans that compose the application.
- ScanDirConfigMXBean uses a set of XML serializable Java beans
- defined in the com.sun.jmx.examples.scandir.config package. These beans are very
- simple Java beans which have been lightly annotated for XML binding.
- CompositeData
- by the MXBean framework, and can be easily introspected with
- jconsole.
- MBeans Must Be Thread-Safe
-
-
-
- sequencer to ensure
- that critical code sections are not executed concurrently. In this
- MBean, we use Semaphore.tryAcquire to lock the sequencer
- semaphore before entering the critical section. If the
- Semaphore.tryAcquire returns true then we enter the critical
- section. If it returns false, we throw an IllegalStateException, stating
- that we couldn't acquire the lock. The code looks like this:
-
- if (!sequencer.tryAcquire())
- throw new IllegalStateException("resource locked");
- try {
- // critical code here ...
- } finally {
- // Always use try/finally to ensure that the semaphore
- // will be released, even if exceptions or errors are raised!
- sequencer.release();
- }
-
- Semaphore.tryAcquire and throwing an exception if
- the semaphore is already locked makes it safer to call other MBeans
- from within the critical section: in potential deadlock situations
- the calling code will get the IllegalStateException
- instead of being blocked on the deadlocked lock.
- IllegalStateException directly, instead of defining
- our own subclass of RuntimeException, which could have had a more
- precise semantics. If you define a new exception for your JMX application,
- you must keep in mind that your client will need to have the class
- of your exception in its classpath to get that exception.
- Otherwise your client will get a completely different exception, indicating a
- deserialization issue.
- Waiting for Notifications
-
-
- // register a notification listener
- ...
- // start a management action
- ...
- // wait for a notification
- ...
- // do something based on whether the expected notification
- // is received
- ...
-
- is not always trivial. However, there's a very easy way to do that: use
- a blocking queue of notifications.
-
- final BlockingQueue<Notification> notifQueue =
- new LinkedBlockingQueue<Notification>();
-
- final NotificationListener listener = new NotificationListener() {
- public void handleNotification(Notification notification,
- Object handback) {
- try {
- // Just put the received notification in the queue.
- // It will be consumed later on.
- //
- notifQueue.put(notification);
- } catch (InterruptedException ex) {
- // OK
- }
- }
- };
-
- // register the listener - possibly also as a JMXConnectionNotification
- // listener to get Notification Lost notification
- ...
- // start management action
- ...
- // wait for notification
- while (expected notif not received and delay not expired) {
- Notification n = notifQueue.poll(3,TimeUnit.SECONDS);
- // if expected notif, do something
- ...
- }
- // if expected notification not received do something else.
- ....
-
- Holding hard references to other MBeans: proxy or direct reference?
-
-
-
- However - holding a hard reference is only advisable
- when both MBeans are created by the same piece of code,
- and the application can ensure that the life cycle
- of each MBean is consistent with regard to the other.
-
- However it holds a direct reference to the ResultLogManager. This makes it possible to pass a direct
- reference to the DirectoryScannerMXBeans,
- which can then log their results
- more efficiently, and would also make it possible to remove
- the log method from the ResultLogManagerMXBean interface - leaving it in the
- ResultLogManager class (possibly as a package method)
- should we wish to do so.
- Agent Class
-
-
- main method to start a standalone
- scandir application.
- main method simply registers a ScanManagerMXBean in the platform MBeanServer, and then waits
- for someone to call ScanManagerMXBean.close.
- ScanManagerMXBean state is switched to
- ScanManagerMXBean.ScanState.CLOSED, the
- ScanManagerMXBean is unregistered, and the application
- terminates (i.e. the main thread completes).
- main method, which performs all the MBean
- registration steps.
- However, it is usually not a bad idea if that class can
- be easily turned into an MBean. Indeed, this will make your
- application easier to integrate in an environment where it would
- no longer be standalone and would no longer control the implementation
- of main. In our example the Agent
- class could be easily turned into an MBean, exposing its three
- init, waitForClose and cleanup
- method. However we didn't go as far as turning it into an MBean since
- the application can be already easily started by registering an instance
- of ScanManagerMXBean.
- Secure Client Class
-
-
-
- main method which creates and
- configures a JMXConnector client to connect with
- a secured scandir daemon. This class will not work with
- the default unsecured agent since it requires mutual authentication.
- ScanDirClient is discussed later in this document.
- ScanDirClient is not really part of the
- application - and is given here only for the sake of
- the example.
- Testing the scandir Example
-
-
CLASSPATH.
- Then in the example root directory (where the build.xml
- file is located) run the following command:
- ant test -Dlibs.junit.classpath=path to junit jar (either 3.8.1 or 3.8.2)
- Run menu.
- Running the scandir Example
-
-
build.xml
- file is located) run the following commands:
- ant jar
-ant run-single -Drun.class=com.sun.jmx.examples.scandir.ScanDirAgent -Djavac.includes=src
- or simply ant run
- ScanDirAgent file
- and run it with Run File in the
- Run menu or simply
- set the jmx-scandir project as main project and
- select Run Main Project from the
- main menu. Both targets will use the configuration
- file provided in the src/etc directory.
-
- Note: You can also run the scandir
- application directly from the
-
-
- java
- command line. Make sure to build the project jar
- first.
-
On Unix systems:
- ant jar
-java -Djava.util.logging.config.file=logging.properties \
- -Dscandir.config.file=src/etc/testconfig.xml \
- -jar dist/jmx-scandir.jar
-
On Windows systems:
- ant jar
-java -Djava.util.logging.config.file=logging.properties
- -Dscandir.config.file=src\etc\testconfig.xml
- -jar dist\jmx-scandir.jarPlaying with JConsole
- ScanDirConfigMXBean.
- Click on its Attributes node and double click on its
- Configuration attribute, to look at
- the loaded configuration - values in bold can
- be expanded by a double-click.
- 
ScanManagerMXBean, click on
- its Notifications node, and subscribe
- for notifications. Then click on the
- Operations node and invoke the
- start() operation:
- 
ResultLogManagerMXBean,
- click on its Attributes node, and
- expand its MemoryLog attribute:
- 
You can see that the directory scan results have - been logged.
-To make the application terminate go back to the
- ScanManagerMXBean and invoke
- close(). The ScanDirAgent
- will receive the notification, step out of
- the application main thread, and the application
- will terminate.
-
This is of course a very limited scenario. Feel free
- to improvise with all the features of the example, creating
- a new configuration -
- ScanManagerMXBean.createOtherConfigurationMBean -
- adding multiple directory scanners to that configuration -
- ScanDirConfigMXBean.addDirectoryScanner -
- then switching the ScanManagerMXBean current
- configuration by changing the value of the ConfigurationMBean
- attribute - ScanManagerMXBean.setConfigurationMBean
- - then applying the new configuration -
- ScanManagerMXBean.applyConfiguration(true) -
- then scheduling repeated directory scans every 10 seconds -
- ScanManagerMXBean.schedule(0,10000) -
- subscribing for notifications, etc...
-
In this section, we will see how to configure and
- start the scandir example so that the JVM agent
- is bootstrapped with a secure JMXConnectorServer. Indeed, until
- now we have only used the insecure local connection,
- which can only be used as long as both the client and
- the server run on the same machine. This section will
- explain how to start the ScanDirAgent so
- that a real secure RMIConnectorServer is started at bootstrap.
-
To achieve this we will: provide our own management.properties, create our own password and access files, - provide a keystore and truststore, - start the ScanDirAgent with the - appropriate system properties. -
The easiest way to configure the
- JVM Agent for Secure Remote
- Connection is to use your own management.properties file.
- In this example, we have copied the default
- $JRE/conf/management/management.properties
- file to the example's src/etc directory and
- modified it in this way:
-
# For setting the JMX RMI agent port use the following line -com.sun.management.jmxremote.port=4545-
# For RMI monitoring with SSL client authentication use the following line -com.sun.management.jmxremote.ssl.need.client.auth=true-
# For using an SSL/TLS protected RMI Registry use the following line -com.sun.management.jmxremote.registry.ssl=true-
# For a non-default password file location use the following line -com.sun.management.jmxremote.password.file=src/etc/password.properties-
# For a non-default password file location use the following line -com.sun.management.jmxremote.access.file=src/etc/access.properties-
You will note that we haven't provided any value
- for the other security properties, like
- com.sun.management.jmxremote.authenticate=true,
- because these properties already default to a value
- which enables security by default.
- Note however that protecting the RMI Registry with SSL
- improves the application security, but only as long as
- mutual authentication is also switched on. Otherwise, just
- anybody would be able to connect to the registry and
- get the RMIServer stub.
-
We do recommend that you use the most secure configuration - when you deploy a JMX agent - which means switching on - SSL protection for the RMI registry and requiring - mutual authentication, as we show in this example. -
-We will use the com.sun.management.config.file
- system property to pass our management.properties
- file to the ScanDirAgent.
-
As explained above, we have created our own - password file - and access file - for access control and authorization. -
-In the password file, we have defined two logins: - guest and admin. The password for - guest is guestpasswd and the password - for admin is adminpasswd. -
-In the access file, we have mapped these two logins - to access rights: the admin login has read-write - access, while the guest login only has read-only. -
-Before starting the ScanDirAgent, you will
- need to restrict access permission to the password file,
- in such a way that nobody but you can read it. Otherwise, the
- JVM Agent will refuse to start the JMXConnectorServer, as it will
- fear that security can be compromised if other parties can
- have read access to the password file. How to restrict
- read access to the password file is explained in detail
- here.
-
As we have seen above, the location - of our access and password files is configured in our own management.properties - file. -
-Using SSL with mutual authentication means that both - client and server will need a keystore and a truststore - to store their own certificates, and the certificates of - the parties they trust. Usually, client and server will - have their own keystore and truststore. -
-For the sake of simplicity - and to get you started - without the tedious necessity of creating your own keystore - and truststore, we are providing a dummy keystore and - truststore, containing a certificate self-signed by duke. - The password for our keystore is password, and the - password for our truststore is trustword. - We suggest that you first get the example running with the - keystore and truststore we are providing before attempting - to use your own keystore and truststore. -
-A secure application will obviously need to use its own - keystore and truststore, and should not rely on the keystore - and truststore we are providing here! -
-How to create your own keystore and truststore, is explained
- in here.
- As shown later,
- we will need to use system properties to pass our truststore
- and keystore to the ScanDirAgent.
-
To start a secure scandir agent, go to the - scandir example root directory and type the - following command:
-On Unix Systems: -
ant jar -java \ - -Djava.util.logging.config.file=logging.properties \ - -Djavax.net.ssl.keyStore=keystore \ - -Djavax.net.ssl.keyStorePassword=password \ - -Djavax.net.ssl.trustStore=truststore \ - -Djavax.net.ssl.trustStorePassword=trustword \ - -Dcom.sun.management.config.file=src/etc/management.properties \ - -Dscandir.config.file=src/etc/testconfig.xml \ - -jar dist/jmx-scandir.jar- -
On Windows Systems: -
ant jar
-java
- -Djava.util.logging.config.file=logging.properties
- -Djavax.net.ssl.keyStore=keystore
- -Djavax.net.ssl.keyStorePassword=password
- -Djavax.net.ssl.trustStore=truststore
- -Djavax.net.ssl.trustStorePassword=trustword
- -Dcom.sun.management.config.file=src\etc\management.properties
- -Dscandir.config.file=src\etc\testconfig.xml
- -jar dist\jmx-scandir.jar
If you start jconsole now, you will see that you - are still able to connect to the agent using the - local connection. However, if you try to connect - through the remote connector, using - localhost:4545, - the connection will fail, even if you provide a correct login/password - pair. Indeed, since the JMXConnectorServer is now protected with SSL, - jconsole must also be configured with the appropriate SSL parameters - so that it can authenticate the server and get authenticated by the - server too as the SSL configuration of the server requires mutual - authentication. -
-The next section will discuss how to connect to the - secure agent. -
- - -We will now see how to connect to the secure agent, - using jconsole, and using a programmatic client. -
-The only special thing you need to do in order to - be able to connect to your secure agent with - jconsole, is to give it a keystore (containing - its client certificate) and a truststore (containing - the certificates of the servers it can trust). - In our example, we use the same keystore/truststore - pair on the client and server side - but this is - not what a real application would do. - Indeed a real application would have different - certificates for the client and the server, and - thus use different keystores (and probably truststores). - More information on SSL authentication can be obtained from the Java™ Secure Socket Extension (JSSE) Reference Guide. -
-To start jconsole with our provided keystore and - truststore, go to the scandir example root directory and - type in the following command: -
jconsole
- -J-Djava.util.logging.config.file=logging.properties
- -J-Djavax.net.ssl.keyStore=keystore
- -J-Djavax.net.ssl.keyStorePassword=password
- -J-Djavax.net.ssl.trustStore=truststore
- -J-Djavax.net.ssl.trustStorePassword=trustword
The -J-Djava.util.logging.config.file=logging.properties
- flag is not mandatory, but passing a logging.properties
- may help you debug connection problems if anything goes wrong.
-
In jconsole connection window, choose to connect to a - remote process, using the address localhost:4545 - and the guest login: -
-
You will see that the agent will let view all the - MBeans and their attributes, but will reject any - attribute modification or remote method invocation. -
-Note: if jconsole fails to connect and show
- you this screen
- you have probably misspelled some of the properties on jconsole
- command line, or you didn't start jconsole from the
- scandir example root directory where our truststore
- and keystore files are located. This article - Troubleshooting connection problems in JConsole - may help
- you figure out what is going wrong.
-
- In this section we will show the steps involved in writing - a programmatic client that will connect to our secure agent. -
-The ScanDirClient is an example class that shows how a
- programmatic client can connect to a secured scandir application.
- This class contains a main method which creates and
- configures a JMXConnector client to connect with
- the secured scandir agent.
-
The secure client differs only from a non secure client in - so far as it needs to use SSL RMI Factories and credentials to - connect to the secure agent. The steps required mainly involve: -
- // Create an environment map to hold connection properties
- // like credentials etc... We will later pass this map
- // to the JMX Connector.
- //
- System.out.println("\nInitialize the environment map");
- final Map<String,Object> env = new HashMap<String,Object>();
-
-
- // Provide the credentials required by the server
- // to successfully perform user authentication
- //
- final String[] credentials = new String[] { "guest" , "guestpasswd" };
- env.put("jmx.remote.credentials", credentials);
-
- SslRMIClientSocketFactory to interact
- with the secure RMI Registry:
-
- // Provide the SSL/TLS-based RMI Client Socket Factory required
- // by the JNDI/RMI Registry Service Provider to communicate with
- // the SSL/TLS-protected RMI Registry
- //
- env.put("com.sun.jndi.rmi.factory.socket",
- new SslRMIClientSocketFactory());
-
-
- // Create the RMI connector client and
- // connect it to the secure RMI connector server.
- // args[0] is the server's host - localhost
- // args[1] is the secure server port - 4545
- //
- System.out.println("\nCreate the RMI connector client and " +
- "connect it to the RMI connector server");
- final JMXServiceURL url = new JMXServiceURL(
- "service:jmx:rmi:///jndi/rmi://"+args[0]+":"+args[1]+
- "/jmxrmi");
- final JMXConnector jmxc = JMXConnectorFactory.connect(url, env);
-
- For this to work, we also need to start the ScanDirClient
- with the appropriate system properties that will point to our
- keystore and truststore. To start the secure
- client, go to the scandir example root directory and type
- the following command:
-
ant jar
-java
- -Djava.util.logging.config.file=logging.properties
- -Djavax.net.ssl.keyStore=keystore
- -Djavax.net.ssl.keyStorePassword=password
- -Djavax.net.ssl.trustStore=truststore
- -Djavax.net.ssl.trustStorePassword=trustword
- -classpath dist/jmx-scandir.jar
- com.sun.jmx.examples.scandir.ScanDirClient localhost 4545
-
You should be seeing this trace: -
--Initialize the environment map - -Create the RMI connector client and connect it to the RMI connector server -Connecting to: service:jmx:rmi:///jndi/rmi://localhost:4545/jmxrmi - -Get the MBeanServerConnection - -Get ScanDirConfigMXBean from ScanManagerMXBean - -Get 'Configuration' attribute on ScanDirConfigMXBean - -Configuration: - -<ScanManager xmlns="jmx:com.sun.jmx.examples.scandir.config" name="testconfig"> - <InitialResultLogConfig> - <LogFileMaxRecords>2048</LogFileMaxRecords> - <LogFileName>build/scandir.log</LogFileName> - <MemoryMaxRecords>128</MemoryMaxRecords> - </InitialResultLogConfig> - <DirectoryScannerList> - <DirectoryScanner name="scan-build"> - <Actions>NOTIFY LOGRESULT</Actions> - <ExcludeFiles/> - <IncludeFiles> - <FileFilter> - <FilePattern>.*\.class</FilePattern> - <SizeExceedsMaxBytes>4096</SizeExceedsMaxBytes> - </FileFilter> - </IncludeFiles> - <RootDirectory>build</RootDirectory> - </DirectoryScanner> - </DirectoryScannerList> -</ScanManager> - -Invoke 'close' on ScanManagerMXBean - -Got expected security exception: java.lang.SecurityException: Access denied! -Invalid access level for requested MBeanServer operation. - -Close the connection to the server - -Bye! Bye! -- |
If the ScanDirClient fails to connect with
- the secure agent, then this article - Troubleshooting connection problems in JConsole - may help
- you figure out what is going wrong. Indeed the connection steps
- performed by the ScanDirClient are very similar to
- those performed by jconsole, and the problems you
- could encounter are identical. Just remember that
- jconsole needs the extra -J flag to pass
- system properties to the VM, which is not needed with regular
- java launcher invocations.
-
- In this document, we have presented an advanced - JMX example, and shown how to run a secure - JMX agent in a production environment. - We have also shown how to connect to such a - secure agent with both jconsole and a programmatic - client. We have also discuss various JMX - design-patterns and best practices. - Readers who would wish to learn more about JMX, and - Monitoring and Management of the JVM, are invited - to follow the links given in reference below. -
--
-
-
diff --git a/jdk/src/sample/share/jmx/jmx-scandir/logging.properties b/jdk/src/sample/share/jmx/jmx-scandir/logging.properties
deleted file mode 100644
index 1714beec628..00000000000
--- a/jdk/src/sample/share/jmx/jmx-scandir/logging.properties
+++ /dev/null
@@ -1,17 +0,0 @@
-handlers= java.util.logging.ConsoleHandler
-
-.level=INFO
-
-
-java.util.logging.FileHandler.pattern = %h/java%u.log
-java.util.logging.FileHandler.limit = 50000
-java.util.logging.FileHandler.count = 1
-java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter
-
-java.util.logging.ConsoleHandler.level = FINEST
-java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
-
-javax.management.level=INFO
-com.sun.jmx.level=INFO
-com.sun.jmx.examples.level=FINE
-
diff --git a/jdk/src/sample/share/jmx/jmx-scandir/manifest.mf b/jdk/src/sample/share/jmx/jmx-scandir/manifest.mf
deleted file mode 100644
index 328e8e5bc3b..00000000000
--- a/jdk/src/sample/share/jmx/jmx-scandir/manifest.mf
+++ /dev/null
@@ -1,3 +0,0 @@
-Manifest-Version: 1.0
-X-COMMENT: Main-Class will be added automatically by build
-
diff --git a/jdk/src/sample/share/jmx/jmx-scandir/nbproject/file-targets.xml b/jdk/src/sample/share/jmx/jmx-scandir/nbproject/file-targets.xml
deleted file mode 100644
index 42da880998b..00000000000
--- a/jdk/src/sample/share/jmx/jmx-scandir/nbproject/file-targets.xml
+++ /dev/null
@@ -1,46 +0,0 @@
-
-
-
-
-DirectoryScanner is an MBean that
- * scans a file system starting at a given root directory,
- * and then looks for files that match a given criteria.
- *
- * When such a file is found, the DirectoryScanner takes
- * the action for which it was configured: emit a notification,
- * and or log a {@link
- * com.sun.jmx.examples.scandir.config.ResultRecord} for this file,
- * and or delete that file.
- *
- * The code that would actually delete the file is commented out - so that
- * nothing valuable is lost if this example is run by mistake on the wrong
- * set of directories.
- * Logged results are logged by sending them to the {@link ResultLogManager}.
- *
- * DirectoryScannerMXBeans are created, initialized, and
- * registered by the {@link ScanManagerMXBean}.
- * The {@link ScanManagerMXBean} will also schedule and run them in
- * background by calling their {@link #scan} method.
- *
Client code is not expected to create or register directly any such
- * MBean. Instead, clients are expected to modify the configuration, using
- * the {@link ScanDirConfigMXBean}, and then apply it, using the {@link
- * ScanManagerMXBean}. Instances of DirectoryScannerMXBeans
- * will then be created and registered (or unregistered and garbage collected)
- * as a side effect of applying that configuration.
- *
This constructor is - * package protected, and this MBean cannot be created by a remote - * client, because it needs a reference to the {@link ResultLogManager}, - * which cannot be provided from remote. - *
- *This is a conscious design choice: {@code DirectoryScanner} MBeans - * are expected to be completely managed (created, registered, unregistered) - * by the {@link ScanManager} which does provide this reference. - *
- * - * @param config This {@code DirectoryScanner} configuration. - * @param logManager The info log manager with which to log the info - * records. - * @throws IllegalArgumentException if one of the parameter is null, or if - * the provided {@code config} doesn't have its {@code name} set, - * or if the {@link DirectoryScannerConfig#getRootDirectory - * root directory} provided in the {@code config} is not acceptable - * (not provided or not found or not readable, etc...). - **/ - public DirectoryScanner(DirectoryScannerConfig config, - ResultLogManager logManager) - throws IllegalArgumentException { - if (logManager == null) - throw new IllegalArgumentException("log=null"); - if (config == null) - throw new IllegalArgumentException("config=null"); - if (config.getName() == null) - throw new IllegalArgumentException("config.name=null"); - - broadcaster = new NotificationBroadcasterSupport(); - - // Clone the config: ensure data encapsulation. - // - this.config = XmlConfigUtils.xmlClone(config); - - // Checks that the provided root directory is valid. - // Throws IllegalArgumentException if it isn't. - // - rootFile = validateRoot(config.getRootDirectory()); - - // Initialize the SetDirectoryScannerMXBean is an MBean that
- * scans a file system starting at a given root directory,
- * and then looks for files that match a given criteria.
- *
- * When such a file is found, the DirectoryScannerMXBean takes
- * the actions for which it was configured: see {@link #scan scan()}.
- *
- * DirectoryScannerMXBeans are created, initialized, and
- * registered by the {@link ScanManagerMXBean}.
- * The {@link ScanManagerMXBean} will also schedule and run them in
- * background by calling their {@link #scan} method.
- *
DirectoryScanner.
- * @throws IOException A connection problem occurred when accessing
- * the underlying resource.
- * @throws InstanceNotFoundException The underlying MBean is not
- * registered in the MBeanServer.
- **/
- public ScanState getState()
- throws IOException, InstanceNotFoundException;
-
- /**
- * Stops the current scan if {@link ScanState#RUNNING running}.
- * After this method completes the state of the application will
- * be {@link ScanState#STOPPED STOPPED}.
- * @throws IOException A connection problem occurred when accessing
- * the underlying resource.
- * @throws InstanceNotFoundException The underlying MBean is not
- * registered in the MBeanServer.
- **/
- public void stop()
- throws IOException, InstanceNotFoundException;
-
- /**
- * Scans the file system starting at the specified {@link #getRootDirectory
- * root directory}.
- * If a file that matches this DirectoryScannerMXBean
- * {@link #getConfiguration} criteria is found,
- * the DirectoryScannerMXBean takes the {@link
- * DirectoryScannerConfig#getActions() actions} for which
- * it was {@link #getConfiguration configured}: emit a notification,
- * and or log a {@link
- * com.sun.jmx.examples.scandir.config.ResultRecord} for this file,
- * and or delete that file.
- *
- * The code that would actually delete the file is commented out - so that - * nothing valuable is lost if this example is run by mistake on the wrong - * set of directories. - *
- *This method returns only when the directory scan is completed, or - * if it was {@link #stop stopped} by another thread. - *
- * @throws IllegalStateException if already {@link ScanState#RUNNING} - * @throws IOException A connection problem occurred when accessing - * the underlying resource. - * @throws InstanceNotFoundException The underlying MBean is not - * registered in the MBeanServer. - **/ - public void scan() - throws IOException, InstanceNotFoundException; - - /** - * Gets the root directory at which thisDirectoryScannerMXBean
- * will start scanning the file system.
- * - * This is a shortcut to {@link #getConfiguration - * getConfiguration()}.{@link - * DirectoryScannerConfig#getRootDirectory - * getRootDirectory()}. - *
- * @return ThisDirectoryScannerMXBean root directory.
- * @throws IOException A connection problem occurred when accessing
- * the underlying resource.
- * @throws InstanceNotFoundException The underlying MBean is not
- * registered in the MBeanServer.
- **/
- public String getRootDirectory()
- throws IOException, InstanceNotFoundException;
-
- /**
- * The configuration data from which this {@link DirectoryScanner} was
- * created.
- *
- * You cannot change this configuration here. You can however
- * {@link ScanDirConfigMXBean#setConfiguration modify} the
- * {@link ScanDirConfigMXBean} configuration, and ask the
- * {@link ScanManagerMXBean} to {@link ScanManagerMXBean#applyConfiguration
- * apply} it. This will get all DirectoryScannerMXBean
- * replaced by new MBeans created from the modified configuration.
- *
DirectoryScannerMXBean configuration data.
- * @throws IOException A connection problem occurred when accessing
- * the underlying resource.
- * @throws InstanceNotFoundException The underlying MBean is not
- * registered in the MBeanServer.
- **/
- public DirectoryScannerConfig getConfiguration()
- throws IOException, InstanceNotFoundException;
-
- /**
- * A short string describing what's happening in current/latest scan.
- * @return a short info string.
- * @throws IOException A connection problem occurred when accessing
- * the underlying resource.
- * @throws InstanceNotFoundException The underlying MBean is not
- * registered in the MBeanServer.
- **/
- public String getCurrentScanInfo()
- throws IOException, InstanceNotFoundException;
-}
diff --git a/jdk/src/sample/share/jmx/jmx-scandir/src/com/sun/jmx/examples/scandir/ResultLogManager.java b/jdk/src/sample/share/jmx/jmx-scandir/src/com/sun/jmx/examples/scandir/ResultLogManager.java
deleted file mode 100644
index a0a4bb9f43d..00000000000
--- a/jdk/src/sample/share/jmx/jmx-scandir/src/com/sun/jmx/examples/scandir/ResultLogManager.java
+++ /dev/null
@@ -1,534 +0,0 @@
-/*
- * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-
-package com.sun.jmx.examples.scandir;
-
-import static com.sun.jmx.examples.scandir.ScanManager.getNextSeqNumber;
-import com.sun.jmx.examples.scandir.config.ResultLogConfig;
-import com.sun.jmx.examples.scandir.config.XmlConfigUtils;
-import com.sun.jmx.examples.scandir.config.ResultRecord;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.logging.Logger;
-import javax.management.MBeanNotificationInfo;
-import javax.management.MBeanRegistration;
-import javax.management.MBeanServer;
-import javax.management.Notification;
-import javax.management.NotificationBroadcasterSupport;
-import javax.management.ObjectName;
-import javax.xml.bind.JAXBException;
-
-/**
- * The ResultLogManager is in charge of managing result logs.
- * {@link DirectoryScanner DirectoryScanners} can be configured to log a
- * {@link ResultRecord} whenever they take action upon a file that
- * matches their set of matching criteria.
- * The ResultLogManagerMXBean is responsible for storing these
- * results in its result logs.
- * The If the name of the MBean is not
- * specified, the MBean can provide a name for its registration. If
- * any exception is raised, the MBean will not be registered in the
- * MBean server. The {@code ResultLogManager} uses this method to supply its own
- * default singleton ObjectName (if name parameter is null).
- * @param server The MBean server in which the MBean will be registered.
- * @param name The object name of the MBean. This name is null if the
- * name parameter to one of the createMBean or registerMBean methods in
- * the MBeanServer interface is null. In that case, this method must
- * return a non-null ObjectName for the new MBean.
- * @return The name under which the MBean is to be registered. This value
- * must not be null. If the name parameter is not null, it will usually
- * but not necessarily be the returned value.
- * @throws Exception This exception will be caught by the MBean server and
- * re-thrown as an MBeanRegistrationException.
- */
- public ObjectName preRegister(MBeanServer server, ObjectName name)
- throws Exception {
- if (name == null)
- name = RESULT_LOG_MANAGER_NAME;
- objectName = name;
- mbeanServer = server;
- return name;
- }
-
- /**
- * Allows the MBean to perform any operations needed after having
- * been registered in the MBean server or after the registration has
- * failed.
- * This implementation does nothing. This implementation does nothing. Closes the log file stream, if it is still open. The The memory log is useful in so far that its content can be interactively
- * returned by the The result logs are intended to be used by e.g. an offline program that
- * would take some actions on the files that were matched by the scanners
- * criteria:
- * The scandir application could be configured to only produce logs
- * (i.e. takes no action but logging the matching files), and the real
- * action (e.g. mail the result log to the engineer which maintains the lab,
- * or parse the log and prepare and send a single mail to the matching
- * files owners, containing the list of file he/she should consider deleting)
- * could be performed by such another program/module.
- *
- * @author Sun Microsystems, 2006 - All rights reserved.
- */
-public interface ResultLogManagerMXBean {
-
- /**
- * Creates a new log file in which to store results.
- * When this method is called, the {@link ResultLogManager} will stop
- * logging in its current log file and use the new specified file instead.
- * If that file already exists, it will be renamed by appending a '~' to
- * its name, and a new empty file with the name specified by
- * basename will be created.
- * Calling this method has no side effect on the {@link
- * com.sun.jmx.examples.scandir.config.ScanManagerConfig#getInitialResultLogConfig
- * InitialResultLogConfig} held in the {@link ScanDirConfigMXBean}
- * configuration. To apply these new values to the
- * {@link ScanDirConfigMXBean}
- * configuration, you must call {@link
- * ScanManagerMXBean#applyCurrentResultLogConfig
- * ScanManagerMXBean.applyCurrentResultLogConfig}.
- *
- * @param basename The name of the new log file. This will be the
- * new name returned by {@link #getLogFileName}.
- * @param maxRecord maximum number of records to log in the specified file
- * before creating a new file. maxRecord will be the
- * new value returned by {@link #getLogFileCapacity}.
- * When that maximum number of
- * records is reached the {@link ResultLogManager} will rename
- * the file by appending a '~' to its name, and a new empty
- * log file will be created.
- * @throws IOException A connection problem occurred when accessing
- * the underlying resource.
- * @throws InstanceNotFoundException The underlying MBean is not
- * registered in the MBeanServer.
- **/
- public void newLogFile(String basename, long maxRecord)
- throws IOException, InstanceNotFoundException;
-
- /**
- * Logs a result record to the active result logs (memory,file,both,or none)
- * depending on how this MBean is currently configured.
- * @see #getLogFileName()
- * @see #getMemoryLogCapacity()
- * @param record The result record to log.
- * @throws IOException A connection problem occurred when accessing
- * the underlying resource.
- * @throws InstanceNotFoundException The underlying MBean is not
- * registered in the MBeanServer.
- */
- public void log(ResultRecord record)
- throws IOException, InstanceNotFoundException;
-
- /**
- * Gets the name of the current result log file.
- *
- * A non positive value - The memory log is a FIFO: when its maximum capacity is reached, its
- * head element is removed to make place for a new element at its tail.
- * The memory log is a FIFO: when its maximum capacity is reached, its
- * head element is removed to make place for a new element at its tail.
- *
- * A non positive value - When that maximum number of
- * records is reached the {@link ResultLogManager} will rename
- * the result log file by appending a '~' to its name, and a new empty
- * log file will be created.
- * If logging to file is disabled calling this method
- * is irrelevant.
- * When that maximum number of
- * records is reached the {@link ResultLogManager} will rename
- * the result log file by appending a '~' to its name, and a new empty
- * log file will be created.
- *
- * The
- * The {@link #main main()} method simply registers a {@link
- * ScanManagerMXBean} in the platform MBeanServer - see {@link #init init},
- * and then waits for someone to call {@link ScanManagerMXBean#close close}
- * on that MBean.
- *
- * When the {@link ScanManagerMXBean} state is switched to {@link
- * ScanManagerMXBean.ScanState#CLOSED CLOSED}, {@link #cleanup cleanup} is
- * called, the {@link ScanManagerMXBean} is unregistered, and the application
- * terminates (i.e. the main thread completes).
- *
- * We can do so because we know that once the ScanManagerMXBean state is
- * switched to 'CLOSED', it will remain 'CLOSED' whatsoever.
- * Had we wanted to wait for 'RUNNING', we would have needed to apply
- * a different strategy - e.g. by taking into account the actual content
- * of the state changed notifications we received.
- * @throws java.io.IOException wait failed - a communication problem occurred.
- * @throws javax.management.JMException wait failed - the MBeanServer threw an exception.
- */
- public void waitForClose() throws IOException, JMException {
-
- // Wait until state is closed
- while(proxy.getState() != ScanState.CLOSED ) {
- try {
- // Wake up at least every 30 seconds - if we missed a
- // notification - we will at least get a chance to
- // call getState(). 30 seconds is obviously quite
- // arbitrary - if this were a real daemon - id'be tempted
- // to wait 30 minutes - knowing that any incoming
- // notification will wake me up anyway.
- // Note: we simply use the state change notifications to
- // react more quickly to state changes: see javadoc above.
- //
- queue.poll(30,TimeUnit.SECONDS);
- } catch (InterruptedException ex) {
- // OK
- }
- }
- }
-
- /**
- * The agent's main: {@link #init registers} a {@link ScanManagerMXBean},
- * {@link #waitForClose waits} until its state is {@link
- * ScanManagerMXBean.ScanState#CLOSED CLOSED}, {@link #cleanup cleanup}
- * and exits.
- * @param args the command line arguments - ignored
- * @throws java.io.IOException A communication problem occurred.
- * @throws javax.management.JMException A JMX problem occurred.
- */
- public static void main(String[] args)
- throws IOException, JMException {
- System.out.println("Initializing ScanManager...");
- final ScanDirAgent agent = new ScanDirAgent();
- agent.init();
- try {
- System.out.println("Waiting for ScanManager to close...");
- agent.waitForClose();
- } finally {
- System.out.println("Cleaning up...");
- agent.cleanup();
- }
- }
-}
diff --git a/jdk/src/sample/share/jmx/jmx-scandir/src/com/sun/jmx/examples/scandir/ScanDirClient.java b/jdk/src/sample/share/jmx/jmx-scandir/src/com/sun/jmx/examples/scandir/ScanDirClient.java
deleted file mode 100644
index 442a607f1cb..00000000000
--- a/jdk/src/sample/share/jmx/jmx-scandir/src/com/sun/jmx/examples/scandir/ScanDirClient.java
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-
-package com.sun.jmx.examples.scandir;
-
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.HashMap;
-import java.util.Map;
-import javax.management.MBeanServerConnection;
-import javax.management.remote.JMXConnector;
-import javax.management.remote.JMXConnectorFactory;
-import javax.management.remote.JMXServiceURL;
-import javax.rmi.ssl.SslRMIClientSocketFactory;
-
-/**
- * The ScanDirClient class is a very simple programmatic client example
- * which is able to connect to a secured JMX scandir application.
- * The program initialize the connection environment map with the
- * appropriate properties and credentials, and then connects to the
- * secure JMX scandir daemon. It gets the application's current configuration and prints it on
- * its The {@link #main main} method takes two arguments: the host on which
- * the server is running (localhost), and the port number
- * that was configured to start the server RMI Connector (4545).
- * The The
- * It will let you also interactively modify that configuration, which you
- * can later save to the file, by calling {@link #save}, or discard, by
- * reloading the file without saving - see {@link #load}.
- *
- * There can be as many
- * Once the current configuration has been loaded (by calling {@link #load})
- * or modified (by calling one of {@link #addDirectoryScanner
- * addDirectoryScanner}, {@link #removeDirectoryScanner removeDirectoryScanner}
- * or {@link #setConfiguration setConfiguration}) it can be pushed
- * to the {@link ScanManagerMXBean} by calling {@link
- * ScanManagerMXBean#applyConfiguration
- * ScanManagerMXBean.applyConfiguration(true)} -
- *
- * The
- * Note: The {@code ScanDirConfigMXBean} can be created by the {@link
- * ScanManagerMXBean}, or directly by a remote client, using
- * {@code createMBean} or {@code registerMBean}.
- * {@code ScanDirConfigMXBean} created by the {@link
- * ScanManagerMXBean} will be unregistered by the
- * {@code ScanManagerMXBean}. {@code ScanDirConfigMXBean} created
- * directly by a remote client will not be unregistered by the
- * {@code ScanManagerMXBean} - this will remain to the responsibility of
- * the code/client that created them.
- * This object is created empty, you should call load() if you want it
- * to load its data from the configuration file.
- *
- * Otherwise, if {@code name} wasn't {@code null} or if a default name could
- * be constructed, the name of the configuration will be set to
- * the value of the ObjectName's {@code name=} key, and the configuration
- * data will always be renamed to reflect this change.
- * This implementation does nothing This implementation does nothing This implementation does nothing The The
- * It will let you also interactively modify that configuration, which you
- * can later save to the file, by calling {@link #save}, or discard, by
- * reloading the file without saving - see {@link #load}.
- *
- * There can be as many
- * Once the current configuration has been loaded (by calling {@link #load})
- * or modified (by calling one of {@link #addDirectoryScanner
- * addDirectoryScanner}, {@link #removeDirectoryScanner removeDirectoryScanner}
- * or {@link #setConfiguration setConfiguration}) it can be pushed
- * to the {@link ScanManagerMXBean} by calling {@link
- * ScanManagerMXBean#applyConfiguration
- * ScanManagerMXBean.applyConfiguration(true)} -
- * Any unsaved modification will be lost. The {@link #getSaveState state}
- * is switched to {@link SaveState#LOADED LOADED}.
- *
- * This action has no effect on the {@link ScanManagerMXBean} until
- * {@link ScanManagerMXBean#getConfigurationMBean ScanManagerMXBean}
- * points to this MBean and {@link ScanManagerMXBean#applyConfiguration
- * ScanManagerMXBean.applyConfiguration} is called.
- * If the configuration file doesn't exists, this method will
- * attempt to create it. Otherwise, the existing file will
- * be renamed by appending a '~' to its name, and a new file
- * will be created, in which the configuration will be saved.
- * The {@link #getSaveState state}
- * is switched to {@link SaveState#SAVED SAVED}.
- *
- * This action has no effect on the {@link ScanManagerMXBean}.
- * If the configuration file doesn't exists, {@link #load} will fail
- * and {@link #save} will attempt to create the file.
- *
- * This method returns the configuration data which is currently held
- * in memory.
- * Call {@link #load} to reload the data from the configuration
- * file, and {@link #save} to save the data to the configuration
- * file.
- *
- * This method replaces the configuration data in memory.
- * The {@link #getSaveState state} is switched to {@link
- * SaveState#MODIFIED MODIFIED}.
- * Calling {@link #load} will reload the data from the configuration
- * file, and all modifications will be lost.
- * Calling {@link #save} will save the modified data to the configuration
- * file.
- *
- * This action has no effect on the {@link ScanManagerMXBean} until
- * {@link ScanManagerMXBean#getConfigurationMBean ScanManagerMXBean}
- * points to this MBean and {@link ScanManagerMXBean#applyConfiguration
- * ScanManagerMXBean.applyConfiguration} is called.
- *
- * This method updates the configuration data in memory, adding
- * a {@link DirectoryScannerConfig} to the {@link
- * ScanManagerConfig#getScanList directory scanner list}.
- * The {@link #getSaveState state} is switched to {@link
- * SaveState#MODIFIED MODIFIED}.
- * Calling {@link #load} will reload the data from the configuration
- * file, and all modifications will be lost.
- * Calling {@link #save} will save the modified data to the configuration
- * file.
- *
- * This action has no effect on the {@link ScanManagerMXBean} until
- * {@link ScanManagerMXBean#getConfigurationMBean ScanManagerMXBean}
- * points to this MBean and {@link ScanManagerMXBean#applyConfiguration
- * ScanManagerMXBean.applyConfiguration} is called.
- *
- * This method updates the configuration data in memory, removing
- * a {@link DirectoryScannerConfig} from the {@link
- * ScanManagerConfig#getScanList directory scanner list}.
- * The {@link #getSaveState state} is switched to {@link
- * SaveState#MODIFIED MODIFIED}.
- * Calling {@link #load} will reload the data from the configuration
- * file, and all modifications will be lost.
- * Calling {@link #save} will save the modified data to the configuration
- * file.
- *
- * This action has no effect on the {@link ScanManagerMXBean} until
- * {@link ScanManagerMXBean#getConfigurationMBean ScanManagerMXBean}
- * points to this MBean and {@link ScanManagerMXBean#applyConfiguration
- * ScanManagerMXBean.applyConfiguration} is called.
- *
- * {@link SaveState#CREATED CREATED} means that the configuration data was just
- * created. It has not been loaded from the configuration file.
- * Calling {@link #load} will load the data from the configuration file.
- * Calling {@link #save} will write the empty data to the configuration
- * file.
- *
- * {@link SaveState#LOADED LOADED} means that the configuration data
- * was loaded from the configuration file.
- *
- * {@link SaveState#MODIFIED MODIFIED} means that the configuration data
- * was modified since it was last loaded or saved.
- * Calling {@link #load} will reload the data from the configuration file,
- * and all modifications will be lost.
- * Calling {@link #save} will write the modified data to the configuration
- * file.
- *
- * {@link SaveState#SAVED SAVED} means that the configuration data
- * was saved to the configuration file.
- *
- * This state doesn't indicate whether this MBean configuration data
- * was {@link ScanManagerMXBean#applyConfiguration applied} by the
- * {@link ScanManagerMXBean}.
- *
- * The
- * The ScanManager MBean is a singleton MBean which controls
- * scan session. The ScanManager name is defined by
- * {@link #SCAN_MANAGER_NAME ScanManager.SCAN_MANAGER_NAME}.
- *
- * The In this implementation, we check that the provided name is
- * either {@code null} or equals to {@link #SCAN_MANAGER_NAME}. If it
- * isn't then we throw an IllegalArgumentException, otherwise we return
- * {@link #SCAN_MANAGER_NAME}. This ensures that there will be a single instance of ScanManager
- * registered in a given MBeanServer, and that it will always be
- * registered with the singleton's {@link #SCAN_MANAGER_NAME}. We do not need to check whether an MBean by that name is
- * already registered because the MBeanServer will perform
- * this check just after having called preRegister().
- * If registration was not successful, the method returns immediately.
- *
- * If registration is successful, register the {@link ResultLogManager}
- * and default {@link ScanDirConfigMXBean}. If registering these
- * MBean fails, the {@code ScanManager} state will be switched to
- * {@link #close CLOSED}, and postRegister ends there.
- * Otherwise the {@code ScanManager} will ask the
- * {@link ScanDirConfigMXBean} to load its configuration.
- * If it succeeds, the configuration will be {@link
- * #applyConfiguration applied}. Otherwise, the method simply returns,
- * assuming that the user will later create/update a configuration and
- * apply it.
- * @param registrationDone Indicates whether or not the MBean has been
- * successfully registered in the MBean server. The value false means
- * that the registration has failed.
- */
- public void postRegister(Boolean registrationDone) {
- if (!registrationDone) return;
- Exception test=null;
- try {
- mbeanServer.registerMBean(log,
- ResultLogManager.RESULT_LOG_MANAGER_NAME);
- final String defconf = getDefaultConfigurationFileName();
- final String conf = System.getProperty("scandir.config.file",defconf);
- final String confname = ScanDirConfig.guessConfigName(conf,defconf);
- final ObjectName defaultProfileName =
- makeMBeanName(ScanDirConfigMXBean.class,confname);
- if (!mbeanServer.isRegistered(defaultProfileName))
- mbeanServer.registerMBean(new ScanDirConfig(conf),
- defaultProfileName);
- config = JMX.newMXBeanProxy(mbeanServer,defaultProfileName,
- ScanDirConfigMXBean.class,true);
- configmap.put(defaultProfileName,config);
- } catch (Exception x) {
- LOG.config("Failed to populate MBeanServer: "+x);
- close();
- return;
- }
- try {
- config.load();
- } catch (Exception x) {
- LOG.finest("No config to load: "+x);
- test = x;
- }
- if (test == null) {
- try {
- applyConfiguration(config.getConfiguration());
- } catch (Exception x) {
- if (LOG.isLoggable(Level.FINEST))
- LOG.log(Level.FINEST,"Failed to apply config: "+x,x);
- LOG.config("Failed to apply config: "+x);
- }
- }
- }
-
- // Unregisters all created DirectoryScanners
- private void unregisterScanners() throws JMException {
- unregisterMBeans(scanmap);
- }
-
- // Unregisters all created ScanDirConfigs
- private void unregisterConfigs() throws JMException {
- unregisterMBeans(configmap);
- }
-
- // Unregisters all MBeans named by the given map
- private void unregisterMBeans(Map
- * The
- * The
- * The {@link #CLOSED} state means
- * that the {@link ScanManagerMXBean} was closed and is no longer usable.
- * This state is used when the {@link ScanManagerMXBean} needs to be
- * unregistered.
- *
- * A scan session is a background task that will sequentially call {@link
- * DirectoryScannerMXBean#scan scan()} on every {@link
- * DirectoryScannerMXBean} configured for this MBean.
- *
- * A scan session is a background task that will sequentially call {@link
- * DirectoryScannerMXBean#scan scan()} on every {@link
- * DirectoryScannerMXBean} configured for this MBean.
- *
- * Scan sessions are started/scheduled by calls to {@link #start start} or
- * {@link #schedule schedule}.
- *
- * When the configuration is applied, all the {@link DirectoryScannerMXBean}
- * created by this MBean will be unregistered, and new {@link
- * DirectoryScannerMXBean} will be created and registered from the
- * new {@link ScanDirConfigMXBean#getConfiguration configuration data}.
- *
- * The initial result log configuration held by the {@link
- * #getConfigurationMBean configuration MBean} will also be pushed to the
- * {@link ResultLogManagerMXBean}. If you don't want to lose your current
- * {@link ResultLogManagerMXBean} configuration, you should therefore call
- * {@link #applyCurrentResultLogConfig
- * applyCurrentResultLogConfig} before calling
- * {@link #applyConfiguration applyConfiguration}
- * This method doesn't {@link #applyConfiguration apply} the new
- * configuration. If you want to apply the new configuration, you should
- * additionally call {@link #applyConfiguration
- * applyConfiguration(true|false)}. Note that you cannot apply a
- * configuration as long as a scan session is scheduled or running.
- * In that case you will need to wait for that session to complete
- * or call {@link #stop} to stop it.
- * You will need to call {@link #setConfigurationMBean
- * setConfigurationMBean} if you
- * want this new {@link ScanDirConfigMXBean} to become the
- * current configuration MBean.
- *
- * This new {@link ScanDirConfigMXBean} will be unregistered automatically
- * by the {@code ScanManagerMXBean} when the {@code ScanManagerMXBean}
- * is unregistered.
- *
- * This class is annotated for XML binding.
- * Tagged deprecated so that a compiler warning is issued.
- * Use {@link #DirectoryScannerConfig(String)
- * DirectoryScannerConfig(String name)} instead.
- *
- * This name is used for the value of the {@code name=} key in the
- * {@code DirectoryScannerMXBean} ObjectName.
- *
- * The
- * This class is annotated for XML binding.
- * If File.isDirectory() && directoryPattern!=null &&
- * File.getName().matches(directoryPattern),
- * then File matches this filter.
- * If File.isDirectory()==false && filePattern!=null &&
- * File.getName().matches(filePattern)==false,
- * then File doesn't match this filter.
- *
- * This class is annotated for XML binding.
- *
- * This class is annotated for XML binding.
- *
- * This class is annotated for XML binding.
- * You should not use this constructor directly, but use
- * {@link #ScanManagerConfig(String)} instead.
- * This constructor is tagged deprecated so that the compiler
- * will generate a warning if it is used by mistake.
- * Once set this value cannot change. If a directory scanner
- * configuration by that name already exists in the list, it will
- * be replaced by the given scan.
- *
- * Performs an atomic write, first writing in {@code
- * In other words, this method XML-serializes the given bean, and
- * XML-deserializes a copy of that bean.
- *
- * In other words, this method XML-serializes the given bean, and
- * XML-deserializes a copy of that bean.
- *
- * In other words, this method XML-serializes the given bean, and
- * XML-deserializes a copy of that bean.
- * This method will rename {@code
- This package defines plain Java Beans, annotated for
- XML bindings, and used to store and model the scandir
- application configuration.
- All the Java Beans defined in this package have been
- designed to be naturally serialized by JAXB.
- Their bean properties were designed to minimize
- the number of XML annotation required, as well as
- making them transparently convertible by the
- JMX MXBean framework.
- The {@link com.sun.jmx.examples.scandir.config.ScanManagerConfig}
- bean corresponds to the root element of the application's configuration.
- From an instance of this element, the
- {@link com.sun.jmx.examples.scandir.ScanManagerMXBean} will be
- able to initialize the
- {@link com.sun.jmx.examples.scandir.ResultLogManagerMXBean} and will
- create, register and initialize
- {@link com.sun.jmx.examples.scandir.DirectoryScannerMXBean DirectoryScannerMXBeans}
- The {@link com.sun.jmx.examples.scandir.config.XmlConfigUtils} class is a simple utility
- classes used to deal with XML and XML configuration files.
- The {@link com.sun.jmx.examples.scandir.config.ResultRecord ResultRecords}
- are used to store the results of directory scans in the result logs
- managed by the {@link com.sun.jmx.examples.scandir.ResultLogManagerMXBean}
-
- This package defines the set of MBeans which compose the
- management interface of the scandir application.
-
- This demo shows how to use bulk data operations with the new JDK8
- Collections API.
- The demo also demonstrates new features of JDK8 such as lambda expressions
- and method/constructor references.
-
- Analyzes a CSV file, finds and collects useful information, computes
- different statistics. For more information, see the source file.
-
- Behaves like the standard Linux tool Grep. For more information, see
- the source file.
-
- Produces a password of desired length. For more information see
- source file.
-
- Counts newlines, words, characters, and the maximum line length of a
- text file. For more information, see the source
- file.
- The {@code exprs} parameter is a comma separated list of expressions
- * where each takes the form:
- * operator is the character {@code '+'}, {@code '-'}, or {@code
- * '='} signifying how permissions are to be changed. {@code '+'} means the
- * permissions are added, {@code '-'} means the permissions are removed, and
- * {@code '='} means the permissions are assigned absolutely.
- *
- * permissions is a sequence of zero or more of the following:
- * {@code 'r'} for read permission, {@code 'w'} for write permission, and
- * {@code 'x'} for execute permission. If permissions is omitted
- * when assigned absolutely, then the permissions are cleared for
- * the owner, group, or others as identified by who. When omitted
- * when adding or removing then the expression is ignored.
- *
- * The following examples demonstrate possible values for the {@code
- * exprs} parameter:
- *
- *
- * Many of these calls may seem unnecessary until you consider
- * that they are placeholders for the secure variant, which is much
- * more involved. See ChannelIOSecure for more information.
- *
- * @author Brad R. Wetmore
- * @author Mark Reinhold
- */
-class ChannelIO {
-
- protected SocketChannel sc;
-
- /*
- * All of the inbound request data lives here until we determine
- * that we've read everything, then we pass that data back to the
- * caller.
- */
- protected ByteBuffer requestBB;
- static private int requestBBSize = 4096;
-
- protected ChannelIO(SocketChannel sc, boolean blocking)
- throws IOException {
- this.sc = sc;
- sc.configureBlocking(blocking);
- }
-
- static ChannelIO getInstance(SocketChannel sc, boolean blocking)
- throws IOException {
- ChannelIO cio = new ChannelIO(sc, blocking);
- cio.requestBB = ByteBuffer.allocate(requestBBSize);
-
- return cio;
- }
-
- SocketChannel getSocketChannel() {
- return sc;
- }
-
- /*
- * Return a ByteBuffer with "remaining" space to work. If you have to
- * reallocate the ByteBuffer, copy the existing info into the new buffer.
- */
- protected void resizeRequestBB(int remaining) {
- if (requestBB.remaining() < remaining) {
- // Expand buffer for large request
- ByteBuffer bb = ByteBuffer.allocate(requestBB.capacity() * 2);
- requestBB.flip();
- bb.put(requestBB);
- requestBB = bb;
- }
- }
-
- /*
- * Perform any handshaking processing.
- *
- * This variant is for Servers without SelectionKeys (e.g.
- * blocking).
- *
- * return true when we're done with handshaking.
- */
- boolean doHandshake() throws IOException {
- return true;
- }
-
- /*
- * Perform any handshaking processing.
- *
- * This variant is for Servers with SelectionKeys, so that
- * we can register for selectable operations (e.g. selectable
- * non-blocking).
- *
- * return true when we're done with handshaking.
- */
- boolean doHandshake(SelectionKey sk) throws IOException {
- return true;
- }
-
- /*
- * Resize (if necessary) the inbound data buffer, and then read more
- * data into the read buffer.
- */
- int read() throws IOException {
- /*
- * Allocate more space if less than 5% remains
- */
- resizeRequestBB(requestBBSize/20);
- return sc.read(requestBB);
- }
-
- /*
- * All data has been read, pass back the request in one buffer.
- */
- ByteBuffer getReadBuf() {
- return requestBB;
- }
-
- /*
- * Write the src buffer into the socket channel.
- */
- int write(ByteBuffer src) throws IOException {
- return sc.write(src);
- }
-
- /*
- * Perform a FileChannel.TransferTo on the socket channel.
- */
- long transferTo(FileChannel fc, long pos, long len) throws IOException {
- return fc.transferTo(pos, len, sc);
- }
-
- /*
- * Flush any outstanding data to the network if possible.
- *
- * This isn't really necessary for the insecure variant, but needed
- * for the secure one where intermediate buffering must take place.
- *
- * Return true if successful.
- */
- boolean dataFlush() throws IOException {
- return true;
- }
-
- /*
- * Start any connection shutdown processing.
- *
- * This isn't really necessary for the insecure variant, but needed
- * for the secure one where intermediate buffering must take place.
- *
- * Return true if successful, and the data has been flushed.
- */
- boolean shutdown() throws IOException {
- return true;
- }
-
- /*
- * Close the underlying connection.
- */
- void close() throws IOException {
- sc.close();
- }
-
-}
diff --git a/jdk/src/sample/share/nio/server/ChannelIOSecure.java b/jdk/src/sample/share/nio/server/ChannelIOSecure.java
deleted file mode 100644
index 74bf652b7f1..00000000000
--- a/jdk/src/sample/share/nio/server/ChannelIOSecure.java
+++ /dev/null
@@ -1,650 +0,0 @@
-/*
- * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-
-import java.io.*;
-import java.nio.*;
-import java.nio.channels.*;
-import javax.net.ssl.*;
-import javax.net.ssl.SSLEngineResult.*;
-
-/**
- * A helper class which performs I/O using the SSLEngine API.
- *
- * Each connection has a SocketChannel and a SSLEngine that is
- * used through the lifetime of the Channel. We allocate byte buffers
- * for use as the outbound and inbound network buffers.
- *
- *
- * There are many, many ways to handle compute and I/O strategies.
- * What follows is a relatively simple one. The reader is encouraged
- * to develop the strategy that best fits the application.
- *
- * In most of the non-blocking operations in this class, we let the
- * Selector tell us when we're ready to attempt an I/O operation (by the
- * application repeatedly calling our methods). Another option would be
- * to attempt the operation and return from the method when no forward
- * progress can be made.
- *
- * There's lots of room for enhancements and improvement in this example.
- *
- * We're checking for SSL/TLS end-of-stream truncation attacks via
- * sslEngine.closeInbound(). When you reach the end of a input stream
- * via a read() returning -1 or an IOException, we call
- * sslEngine.closeInbound() to signal to the sslEngine that no more
- * input will be available. If the peer's close_notify message has not
- * yet been received, this could indicate a trucation attack, in which
- * an attacker is trying to prematurely close the connection. The
- * closeInbound() will throw an exception if this condition were
- * present.
- *
- * @author Brad R. Wetmore
- * @author Mark Reinhold
- */
-class ChannelIOSecure extends ChannelIO {
-
- private SSLEngine sslEngine = null;
-
- private int appBBSize;
- private int netBBSize;
-
- /*
- * All I/O goes through these buffers.
- *
- * It might be nice to use a cache of ByteBuffers so we're
- * not alloc/dealloc'ing ByteBuffer's for each new SSLEngine.
- *
- * We use our superclass' requestBB for our application input buffer.
- * Outbound application data is supplied to us by our callers.
- */
- private ByteBuffer inNetBB;
- private ByteBuffer outNetBB;
-
- /*
- * An empty ByteBuffer for use when one isn't available, say
- * as a source buffer during initial handshake wraps or for close
- * operations.
- */
- private static ByteBuffer hsBB = ByteBuffer.allocate(0);
-
- /*
- * The FileChannel we're currently transferTo'ing (reading).
- */
- private ByteBuffer fileChannelBB = null;
-
- /*
- * During our initial handshake, keep track of the next
- * SSLEngine operation that needs to occur:
- *
- * NEED_WRAP/NEED_UNWRAP
- *
- * Once the initial handshake has completed, we can short circuit
- * handshake checks with initialHSComplete.
- */
- private HandshakeStatus initialHSStatus;
- private boolean initialHSComplete;
-
- /*
- * We have received the shutdown request by our caller, and have
- * closed our outbound side.
- */
- private boolean shutdown = false;
-
- /*
- * Constructor for a secure ChannelIO variant.
- */
- protected ChannelIOSecure(SocketChannel sc, boolean blocking,
- SSLContext sslc) throws IOException {
- super(sc, blocking);
-
- /*
- * We're a server, so no need to use host/port variant.
- *
- * The first call for a server is a NEED_UNWRAP.
- */
- sslEngine = sslc.createSSLEngine();
- sslEngine.setUseClientMode(false);
- initialHSStatus = HandshakeStatus.NEED_UNWRAP;
- initialHSComplete = false;
-
- // Create a buffer using the normal expected packet size we'll
- // be getting. This may change, depending on the peer's
- // SSL implementation.
- netBBSize = sslEngine.getSession().getPacketBufferSize();
- inNetBB = ByteBuffer.allocate(netBBSize);
- outNetBB = ByteBuffer.allocate(netBBSize);
- outNetBB.position(0);
- outNetBB.limit(0);
- }
-
- /*
- * Static factory method for creating a secure ChannelIO object.
- *
- * We need to allocate different sized application data buffers
- * based on whether we're secure or not. We can't determine
- * this until our sslEngine is created.
- */
- static ChannelIOSecure getInstance(SocketChannel sc, boolean blocking,
- SSLContext sslc) throws IOException {
-
- ChannelIOSecure cio = new ChannelIOSecure(sc, blocking, sslc);
-
- // Create a buffer using the normal expected application size we'll
- // be getting. This may change, depending on the peer's
- // SSL implementation.
- cio.appBBSize = cio.sslEngine.getSession().getApplicationBufferSize();
- cio.requestBB = ByteBuffer.allocate(cio.appBBSize);
-
- return cio;
- }
-
- /*
- * Calls up to the superclass to adjust the buffer size
- * by an appropriate increment.
- */
- protected void resizeRequestBB() {
- resizeRequestBB(appBBSize);
- }
-
- /*
- * Adjust the inbount network buffer to an appropriate size.
- */
- private void resizeResponseBB() {
- ByteBuffer bb = ByteBuffer.allocate(netBBSize);
- inNetBB.flip();
- bb.put(inNetBB);
- inNetBB = bb;
- }
-
- /*
- * Writes bb to the SocketChannel.
- *
- * Returns true when the ByteBuffer has no remaining data.
- */
- private boolean tryFlush(ByteBuffer bb) throws IOException {
- super.write(bb);
- return !bb.hasRemaining();
- }
-
- /*
- * Perform any handshaking processing.
- *
- * This variant is for Servers without SelectionKeys (e.g.
- * blocking).
- */
- boolean doHandshake() throws IOException {
- return doHandshake(null);
- }
-
- /*
- * Perform any handshaking processing.
- *
- * If a SelectionKey is passed, register for selectable
- * operations.
- *
- * In the blocking case, our caller will keep calling us until
- * we finish the handshake. Our reads/writes will block as expected.
- *
- * In the non-blocking case, we just received the selection notification
- * that this channel is ready for whatever the operation is, so give
- * it a try.
- *
- * return:
- * true when handshake is done.
- * false while handshake is in progress
- */
- boolean doHandshake(SelectionKey sk) throws IOException {
-
- SSLEngineResult result;
-
- if (initialHSComplete) {
- return initialHSComplete;
- }
-
- /*
- * Flush out the outgoing buffer, if there's anything left in
- * it.
- */
- if (outNetBB.hasRemaining()) {
-
- if (!tryFlush(outNetBB)) {
- return false;
- }
-
- // See if we need to switch from write to read mode.
-
- switch (initialHSStatus) {
-
- /*
- * Is this the last buffer?
- */
- case FINISHED:
- initialHSComplete = true;
- // Fall-through to reregister need for a Read.
-
- case NEED_UNWRAP:
- if (sk != null) {
- sk.interestOps(SelectionKey.OP_READ);
- }
- break;
- }
-
- return initialHSComplete;
- }
-
-
- switch (initialHSStatus) {
-
- case NEED_UNWRAP:
- if (sc.read(inNetBB) == -1) {
- sslEngine.closeInbound();
- return initialHSComplete;
- }
-
-needIO:
- while (initialHSStatus == HandshakeStatus.NEED_UNWRAP) {
- resizeRequestBB(); // expected room for unwrap
- inNetBB.flip();
- result = sslEngine.unwrap(inNetBB, requestBB);
- inNetBB.compact();
-
- initialHSStatus = result.getHandshakeStatus();
-
- switch (result.getStatus()) {
-
- case OK:
- switch (initialHSStatus) {
- case NOT_HANDSHAKING:
- throw new IOException(
- "Not handshaking during initial handshake");
-
- case NEED_TASK:
- initialHSStatus = doTasks();
- break;
-
- case FINISHED:
- initialHSComplete = true;
- break needIO;
- }
-
- break;
-
- case BUFFER_UNDERFLOW:
- // Resize buffer if needed.
- netBBSize = sslEngine.getSession().getPacketBufferSize();
- if (netBBSize > inNetBB.capacity()) {
- resizeResponseBB();
- }
-
- /*
- * Need to go reread the Channel for more data.
- */
- if (sk != null) {
- sk.interestOps(SelectionKey.OP_READ);
- }
- break needIO;
-
- case BUFFER_OVERFLOW:
- // Reset the application buffer size.
- appBBSize =
- sslEngine.getSession().getApplicationBufferSize();
- break;
-
- default: //CLOSED:
- throw new IOException("Received" + result.getStatus() +
- "during initial handshaking");
- }
- } // "needIO" block.
-
- /*
- * Just transitioned from read to write.
- */
- if (initialHSStatus != HandshakeStatus.NEED_WRAP) {
- break;
- }
-
- // Fall through and fill the write buffers.
-
- case NEED_WRAP:
- /*
- * The flush above guarantees the out buffer to be empty
- */
- outNetBB.clear();
- result = sslEngine.wrap(hsBB, outNetBB);
- outNetBB.flip();
-
- initialHSStatus = result.getHandshakeStatus();
-
- switch (result.getStatus()) {
- case OK:
-
- if (initialHSStatus == HandshakeStatus.NEED_TASK) {
- initialHSStatus = doTasks();
- }
-
- if (sk != null) {
- sk.interestOps(SelectionKey.OP_WRITE);
- }
-
- break;
-
- default: // BUFFER_OVERFLOW/BUFFER_UNDERFLOW/CLOSED:
- throw new IOException("Received" + result.getStatus() +
- "during initial handshaking");
- }
- break;
-
- default: // NOT_HANDSHAKING/NEED_TASK/FINISHED
- throw new RuntimeException("Invalid Handshaking State" +
- initialHSStatus);
- } // switch
-
- return initialHSComplete;
- }
-
- /*
- * Do all the outstanding handshake tasks in the current Thread.
- */
- private SSLEngineResult.HandshakeStatus doTasks() {
-
- Runnable runnable;
-
- /*
- * We could run this in a separate thread, but
- * do in the current for now.
- */
- while ((runnable = sslEngine.getDelegatedTask()) != null) {
- runnable.run();
- }
- return sslEngine.getHandshakeStatus();
- }
-
- /*
- * Read the channel for more information, then unwrap the
- * (hopefully application) data we get.
- *
- * If we run out of data, we'll return to our caller (possibly using
- * a Selector) to get notification that more is available.
- *
- * Each call to this method will perform at most one underlying read().
- */
- int read() throws IOException {
- SSLEngineResult result;
-
- if (!initialHSComplete) {
- throw new IllegalStateException();
- }
-
- int pos = requestBB.position();
-
- if (sc.read(inNetBB) == -1) {
- sslEngine.closeInbound(); // probably throws exception
- return -1;
- }
-
- do {
- resizeRequestBB(); // expected room for unwrap
- inNetBB.flip();
- result = sslEngine.unwrap(inNetBB, requestBB);
- inNetBB.compact();
-
- /*
- * Could check here for a renegotation, but we're only
- * doing a simple read/write, and won't have enough state
- * transitions to do a complete handshake, so ignore that
- * possibility.
- */
- switch (result.getStatus()) {
-
- case BUFFER_OVERFLOW:
- // Reset the application buffer size.
- appBBSize = sslEngine.getSession().getApplicationBufferSize();
- break;
-
- case BUFFER_UNDERFLOW:
- // Resize buffer if needed.
- netBBSize = sslEngine.getSession().getPacketBufferSize();
- if (netBBSize > inNetBB.capacity()) {
- resizeResponseBB();
-
- break; // break, next read will support larger buffer.
- }
- case OK:
- if (result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
- doTasks();
- }
- break;
-
- default:
- throw new IOException("sslEngine error during data read: " +
- result.getStatus());
- }
- } while ((inNetBB.position() != 0) &&
- result.getStatus() != Status.BUFFER_UNDERFLOW);
-
- return (requestBB.position() - pos);
- }
-
- /*
- * Try to write out as much as possible from the src buffer.
- */
- int write(ByteBuffer src) throws IOException {
-
- if (!initialHSComplete) {
- throw new IllegalStateException();
- }
-
- return doWrite(src);
- }
-
- /*
- * Try to flush out any existing outbound data, then try to wrap
- * anything new contained in the src buffer.
- *
- * Return the number of bytes actually consumed from the buffer,
- * but the data may actually be still sitting in the output buffer,
- * waiting to be flushed.
- */
- private int doWrite(ByteBuffer src) throws IOException {
- int retValue = 0;
-
- if (outNetBB.hasRemaining() && !tryFlush(outNetBB)) {
- return retValue;
- }
-
- /*
- * The data buffer is empty, we can reuse the entire buffer.
- */
- outNetBB.clear();
-
- SSLEngineResult result = sslEngine.wrap(src, outNetBB);
- retValue = result.bytesConsumed();
-
- outNetBB.flip();
-
- switch (result.getStatus()) {
-
- case OK:
- if (result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
- doTasks();
- }
- break;
-
- default:
- throw new IOException("sslEngine error during data write: " +
- result.getStatus());
- }
-
- /*
- * Try to flush the data, regardless of whether or not
- * it's been selected. Odds of a write buffer being full
- * is less than a read buffer being empty.
- */
- if (outNetBB.hasRemaining()) {
- tryFlush(outNetBB);
- }
-
- return retValue;
- }
-
- /*
- * Perform a FileChannel.TransferTo on the socket channel.
- *
- * We have to copy the data into an intermediary app ByteBuffer
- * first, then send it through the SSLEngine.
- *
- * We return the number of bytes actually read out of the
- * filechannel. However, the data may actually be stuck
- * in the fileChannelBB or the outNetBB. The caller
- * is responsible for making sure to call dataFlush()
- * before shutting down.
- */
- long transferTo(FileChannel fc, long pos, long len) throws IOException {
-
- if (!initialHSComplete) {
- throw new IllegalStateException();
- }
-
- if (fileChannelBB == null) {
- fileChannelBB = ByteBuffer.allocate(appBBSize);
- fileChannelBB.limit(0);
- }
-
- fileChannelBB.compact();
- int fileRead = fc.read(fileChannelBB);
- fileChannelBB.flip();
-
- /*
- * We ignore the return value here, we return the
- * number of bytes actually consumed from the file.
- * We'll flush the output buffer before we start shutting down.
- */
- doWrite(fileChannelBB);
-
- return fileRead;
- }
-
- /*
- * Flush any remaining data.
- *
- * Return true when the fileChannelBB and outNetBB are empty.
- */
- boolean dataFlush() throws IOException {
- boolean fileFlushed = true;
-
- if ((fileChannelBB != null) && fileChannelBB.hasRemaining()) {
- doWrite(fileChannelBB);
- fileFlushed = !fileChannelBB.hasRemaining();
- } else if (outNetBB.hasRemaining()) {
- tryFlush(outNetBB);
- }
-
- return (fileFlushed && !outNetBB.hasRemaining());
- }
-
- /*
- * Begin the shutdown process.
- *
- * Close out the SSLEngine if not already done so, then
- * wrap our outgoing close_notify message and try to send it on.
- *
- * Return true when we're done passing the shutdown messsages.
- */
- boolean shutdown() throws IOException {
-
- if (!shutdown) {
- sslEngine.closeOutbound();
- shutdown = true;
- }
-
- if (outNetBB.hasRemaining() && tryFlush(outNetBB)) {
- return false;
- }
-
- /*
- * By RFC 2616, we can "fire and forget" our close_notify
- * message, so that's what we'll do here.
- */
- outNetBB.clear();
- SSLEngineResult result = sslEngine.wrap(hsBB, outNetBB);
- if (result.getStatus() != Status.CLOSED) {
- throw new SSLException("Improper close state");
- }
- outNetBB.flip();
-
- /*
- * We won't wait for a select here, but if this doesn't work,
- * we'll cycle back through on the next select.
- */
- if (outNetBB.hasRemaining()) {
- tryFlush(outNetBB);
- }
-
- return (!outNetBB.hasRemaining() &&
- (result.getHandshakeStatus() != HandshakeStatus.NEED_WRAP));
- }
-
- /*
- * close() is not overridden
- */
-}
diff --git a/jdk/src/sample/share/nio/server/Content.java b/jdk/src/sample/share/nio/server/Content.java
deleted file mode 100644
index 52e06faca03..00000000000
--- a/jdk/src/sample/share/nio/server/Content.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-
-/**
- * An Sendable interface extension that adds additional
- * methods for additional information, such as Files
- * or Strings.
- *
- * @author Mark Reinhold
- * @author Brad R. Wetmore
- */
-interface Content extends Sendable {
-
- String type();
-
- // Returns -1 until prepare() invoked
- long length();
-
-}
diff --git a/jdk/src/sample/share/nio/server/Dispatcher.java b/jdk/src/sample/share/nio/server/Dispatcher.java
deleted file mode 100644
index 9474c12765f..00000000000
--- a/jdk/src/sample/share/nio/server/Dispatcher.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-
-import java.io.*;
-import java.nio.channels.*;
-
-/**
- * Base class for the Dispatchers.
- *
- * Servers use these to obtain ready status, and then to dispatch jobs.
- *
- * @author Mark Reinhold
- * @author Brad R. Wetmore
- */
-interface Dispatcher extends Runnable {
-
- void register(SelectableChannel ch, int ops, Handler h)
- throws IOException;
-
-}
diff --git a/jdk/src/sample/share/nio/server/Dispatcher1.java b/jdk/src/sample/share/nio/server/Dispatcher1.java
deleted file mode 100644
index 533e4b81e8b..00000000000
--- a/jdk/src/sample/share/nio/server/Dispatcher1.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-
-import java.io.*;
-import java.nio.channels.*;
-import java.util.*;
-
-/**
- * A single-threaded dispatcher.
- *
- * When a SelectionKey is ready, it dispatches the job in this
- * thread.
- *
- * @author Mark Reinhold
- * @author Brad R. Wetmore
- */
-class Dispatcher1 implements Dispatcher {
-
- private Selector sel;
-
- Dispatcher1() throws IOException {
- sel = Selector.open();
- }
-
- // Doesn't really need to be runnable
- public void run() {
- for (;;) {
- try {
- dispatch();
- } catch (IOException x) {
- x.printStackTrace();
- }
- }
- }
-
- private void dispatch() throws IOException {
- sel.select();
- for (Iterator i = sel.selectedKeys().iterator(); i.hasNext(); ) {
- SelectionKey sk = (SelectionKey)i.next();
- i.remove();
- Handler h = (Handler)sk.attachment();
- h.handle(sk);
- }
- }
-
- public void register(SelectableChannel ch, int ops, Handler h)
- throws IOException {
- ch.register(sel, ops, h);
- }
-}
diff --git a/jdk/src/sample/share/nio/server/DispatcherN.java b/jdk/src/sample/share/nio/server/DispatcherN.java
deleted file mode 100644
index 7b601b0faa4..00000000000
--- a/jdk/src/sample/share/nio/server/DispatcherN.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-
-import java.io.*;
-import java.nio.channels.*;
-import java.util.*;
-
-/**
- * A Multi-threaded dispatcher.
- *
- * In this example, one thread does accepts, and the second
- * does read/writes.
- *
- * @author Mark Reinhold
- * @author Brad R. Wetmore
- */
-class DispatcherN implements Dispatcher {
-
- private Selector sel;
-
- DispatcherN() throws IOException {
- sel = Selector.open();
- }
-
- public void run() {
- for (;;) {
- try {
- dispatch();
- } catch (IOException x) {
- x.printStackTrace();
- }
- }
- }
-
- private Object gate = new Object();
-
- private void dispatch() throws IOException {
- sel.select();
- for (Iterator i = sel.selectedKeys().iterator(); i.hasNext(); ) {
- SelectionKey sk = (SelectionKey)i.next();
- i.remove();
- Handler h = (Handler)sk.attachment();
- h.handle(sk);
- }
- synchronized (gate) { }
- }
-
- public void register(SelectableChannel ch, int ops, Handler h)
- throws IOException {
- synchronized (gate) {
- sel.wakeup();
- ch.register(sel, ops, h);
- }
- }
-
-}
diff --git a/jdk/src/sample/share/nio/server/FileContent.java b/jdk/src/sample/share/nio/server/FileContent.java
deleted file mode 100644
index 82c44a9b2be..00000000000
--- a/jdk/src/sample/share/nio/server/FileContent.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-
-import java.io.*;
-import java.net.*;
-import java.nio.channels.*;
-import java.nio.charset.*;
-
-/**
- * A Content type that provides for transferring files.
- *
- * @author Mark Reinhold
- * @author Brad R. Wetmore
- */
-class FileContent implements Content {
-
- private static File ROOT = new File("root");
-
- private File fn;
-
- FileContent(URI uri) {
- fn = new File(ROOT,
- uri.getPath()
- .replace('/',
- File.separatorChar));
- }
-
- private String type = null;
-
- public String type() {
- if (type != null)
- return type;
- String nm = fn.getName();
- if (nm.endsWith(".html"))
- type = "text/html; charset=iso-8859-1";
- else if ((nm.indexOf('.') < 0) || nm.endsWith(".txt"))
- type = "text/plain; charset=iso-8859-1";
- else
- type = "application/octet-stream";
- return type;
- }
-
- private FileChannel fc = null;
- private long length = -1;
- private long position = -1; // NB only; >= 0 if transferring
-
- public long length() {
- return length;
- }
-
- public void prepare() throws IOException {
- if (fc == null)
- fc = new RandomAccessFile(fn, "r").getChannel();
- length = fc.size();
- position = 0; // NB only
- }
-
- public boolean send(ChannelIO cio) throws IOException {
- if (fc == null)
- throw new IllegalStateException();
- if (position < 0) // NB only
- throw new IllegalStateException();
-
- /*
- * Short-circuit if we're already done.
- */
- if (position >= length) {
- return false;
- }
-
- position += cio.transferTo(fc, position, length - position);
- return (position < length);
- }
-
- public void release() throws IOException {
- if (fc != null) {
- fc.close();
- fc = null;
- }
- }
-}
diff --git a/jdk/src/sample/share/nio/server/Handler.java b/jdk/src/sample/share/nio/server/Handler.java
deleted file mode 100644
index 110feb7a0e3..00000000000
--- a/jdk/src/sample/share/nio/server/Handler.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-
-import java.io.*;
-import java.nio.channels.*;
-
-/**
- * Base class for the Handlers.
- *
- * @author Mark Reinhold
- * @author Brad R. Wetmore
- */
-interface Handler {
-
- void handle(SelectionKey sk) throws IOException;
-
-}
diff --git a/jdk/src/sample/share/nio/server/MalformedRequestException.java b/jdk/src/sample/share/nio/server/MalformedRequestException.java
deleted file mode 100644
index 89b0db65ddb..00000000000
--- a/jdk/src/sample/share/nio/server/MalformedRequestException.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-
-/**
- * Exception class used when a request can't be properly parsed.
- *
- * @author Mark Reinhold
- * @author Brad R. Wetmore
- */
-class MalformedRequestException extends Exception {
-
- MalformedRequestException() { }
-
- MalformedRequestException(String msg) {
- super(msg);
- }
-
- MalformedRequestException(Exception x) {
- super(x);
- }
-}
diff --git a/jdk/src/sample/share/nio/server/N1.java b/jdk/src/sample/share/nio/server/N1.java
deleted file mode 100644
index d02bc931c23..00000000000
--- a/jdk/src/sample/share/nio/server/N1.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-
-import java.nio.channels.*;
-
-/**
- * A non-blocking/single-threaded server. All accept() and
- * read()/write() operations are performed by a single thread, but only
- * after being selected for those operations by a Selector.
- *
- * @author Mark Reinhold
- * @author Brad R. Wetmore
- */
-public class N1 extends Server {
-
- N1(int port, int backlog, boolean secure) throws Exception {
- super(port, backlog, secure);
- ssc.configureBlocking(false);
- }
-
- void runServer() throws Exception {
- Dispatcher d = new Dispatcher1();
- d.register(ssc, SelectionKey.OP_ACCEPT,
- new AcceptHandler(ssc, d, sslContext));
- d.run();
- }
-}
diff --git a/jdk/src/sample/share/nio/server/N2.java b/jdk/src/sample/share/nio/server/N2.java
deleted file mode 100644
index 2a216127cb6..00000000000
--- a/jdk/src/sample/share/nio/server/N2.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-
-/**
- * A non-blocking/dual-threaded which performs accept()s in one thread,
- * and services requests in a second. Both threads use select().
- *
- * @author Mark Reinhold
- * @author Brad R. Wetmore
- */
-public class N2 extends Server {
-
- N2(int port, int backlog, boolean secure) throws Exception {
- super(port, backlog, secure);
- }
-
- void runServer() throws Exception {
- Dispatcher d = new DispatcherN();
- Acceptor a = new Acceptor(ssc, d, sslContext);
- new Thread(a).start();
- d.run();
- }
-}
diff --git a/jdk/src/sample/share/nio/server/README.txt b/jdk/src/sample/share/nio/server/README.txt
deleted file mode 100644
index c012b82846b..00000000000
--- a/jdk/src/sample/share/nio/server/README.txt
+++ /dev/null
@@ -1,279 +0,0 @@
- A Simple NIO-based HTTP/HTTPS Server Example
-
-
-INTRODUCTION
-============
-This directory contains a simple HTTP/HTTPS server. HTTP/HTTPS are two
-common network protocols that provide for data transfer, and are more
-fully described in RFC 2616 and RFC 2818 (Available at
-http://www.ietf.org ). HTTPS is essentially HTTP after the connection
-has been secured with SSL/TLS. TLS is the successor to SSL, and is
-described in RFC 2246.
-
-This server was written to demonstrate some of the functionality new to
-the Java 2 platform. The demo is not meant to be a full tutorial, and
-assumes the reader has some familiarity with the subject matter.
-
-In particular, it shows:
-
- New I/O (java.nio, java.nio.channels, java.util.regex, java.nio.charset)
-
- Introduced in version 1.4 of the platform, NIO was designed to
- overcome some of the scalability limitations found in the
- existing blocking java.net.* API's, and to address other
- concepts such as Regular Expression parsing and Character
- Sets.
-
- This server demonstrates:
-
- ByteBuffer
- Blocking and Non-Blocking I/O
- SocketChannel
- ServerSocketChannel
- Selector
- CharacterSet
- Pattern matching using Regular Expressions
-
- JSSE (javax.net.ssl)
-
- Introduced in version 1.4 of the platform, JSSE provides
- network security using SSL/TLS for java.net.Socket-based
- traffic. In version 1.5, the SSLEngine API was introduced
- which separates the SSL/TLS functionality from the underlying
- I/O model. By making this separation, applications can adapt
- I/O and compute strategies to best fit their circumstances.
-
- This server demonstrates:
-
- Using SSLEngine to create a HTTPS server
- Creating simple key material for use with HTTPS
-
- Concurrency Library (java.util.concurrent)
-
- Introduced in version 1.5 of the platform, the concurrency
- library provides a mechanism which decouples task submission
- from the mechanics of how each task will be run.
-
- This server demonstrates:
-
- A ThreadPool with a fixed number of threads, which is
- based on the number of available processors.
-
-
-SETUP
-=====
-
-The server must be built on version 1.5 (or later) of the platform.
-Invoking the following should be sufficient:
-
- % mkdir build
- % javac -d build *.java
-
-The following creates the document root:
-
- % mkdir root
-
-All documents should be placed in this directory.
-
-For HTTPS, the server authenticates itself to clients by using simple
-Public Key Infrastructure (PKI) credentials in the form of
-X509Certificates. You must create the server's credentials before
-attempting to run the server in "-secure" mode. The server is
-currently hardcoded to look for its credentials in a file called
-"testkeys".
-
-In this example, we'll create credentials for a fictional widget web
-site owned by the ubiquitous "Xyzzy, Inc.". When you run this in your
-own environment, replace "widgets.xyzzy.com" with the hostname of your
-server.
-
-The easiest way to create the SSL/TLS credentials is to use the
-java keytool, by doing the following:
-
- (
- * The static method parse() is responsible for creating this
- * object.
- *
- * @author Mark Reinhold
- * @author Brad R. Wetmore
- */
-class Request {
-
- /**
- * A helper class for parsing HTTP command actions.
- */
- static class Action {
-
- private String name;
- private Action(String name) { this.name = name; }
- public String toString() { return name; }
-
- static Action GET = new Action("GET");
- static Action PUT = new Action("PUT");
- static Action POST = new Action("POST");
- static Action HEAD = new Action("HEAD");
-
- static Action parse(String s) {
- if (s.equals("GET"))
- return GET;
- if (s.equals("PUT"))
- return PUT;
- if (s.equals("POST"))
- return POST;
- if (s.equals("HEAD"))
- return HEAD;
- throw new IllegalArgumentException(s);
- }
- }
-
- private Action action;
- private String version;
- private URI uri;
-
- Action action() { return action; }
- String version() { return version; }
- URI uri() { return uri; }
-
- private Request(Action a, String v, URI u) {
- action = a;
- version = v;
- uri = u;
- }
-
- public String toString() {
- return (action + " " + version + " " + uri);
- }
-
- static boolean isComplete(ByteBuffer bb) {
- int p = bb.position() - 4;
- if (p < 0)
- return false;
- return (((bb.get(p + 0) == '\r') &&
- (bb.get(p + 1) == '\n') &&
- (bb.get(p + 2) == '\r') &&
- (bb.get(p + 3) == '\n')));
- }
-
- private static Charset ascii = Charset.forName("US-ASCII");
-
- /*
- * The expected message format is first compiled into a pattern,
- * and is then compared against the inbound character buffer to
- * determine if there is a match. This convienently tokenizes
- * our request into usable pieces.
- *
- * This uses Matcher "expression capture groups" to tokenize
- * requests like:
- *
- * GET /dir/file HTTP/1.1
- * Host: hostname
- *
- * into:
- *
- * group[1] = "GET"
- * group[2] = "/dir/file"
- * group[3] = "1.1"
- * group[4] = "hostname"
- *
- * The text in between the parens are used to captured the regexp text.
- */
- private static Pattern requestPattern
- = Pattern.compile("\\A([A-Z]+) +([^ ]+) +HTTP/([0-9\\.]+)$"
- + ".*^Host: ([^ ]+)$.*\r\n\r\n\\z",
- Pattern.MULTILINE | Pattern.DOTALL);
-
- static Request parse(ByteBuffer bb) throws MalformedRequestException {
-
- CharBuffer cb = ascii.decode(bb);
- Matcher m = requestPattern.matcher(cb);
- if (!m.matches())
- throw new MalformedRequestException();
- Action a;
- try {
- a = Action.parse(m.group(1));
- } catch (IllegalArgumentException x) {
- throw new MalformedRequestException();
- }
- URI u;
- try {
- u = new URI("http://"
- + m.group(4)
- + m.group(2));
- } catch (URISyntaxException x) {
- throw new MalformedRequestException();
- }
- return new Request(a, m.group(3), u);
- }
-}
diff --git a/jdk/src/sample/share/nio/server/RequestHandler.java b/jdk/src/sample/share/nio/server/RequestHandler.java
deleted file mode 100644
index 91d2bda6711..00000000000
--- a/jdk/src/sample/share/nio/server/RequestHandler.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-
-import java.io.*;
-import java.nio.*;
-import java.nio.channels.*;
-
-/**
- * Primary driver class used by non-blocking Servers to receive,
- * prepare, send, and shutdown requests.
- *
- * @author Mark Reinhold
- * @author Brad R. Wetmore
- */
-class RequestHandler implements Handler {
-
- private ChannelIO cio;
- private ByteBuffer rbb = null;
-
- private boolean requestReceived = false;
- private Request request = null;
- private Reply reply = null;
-
- private static int created = 0;
-
- RequestHandler(ChannelIO cio) {
- this.cio = cio;
-
- // Simple heartbeat to let user know we're alive.
- synchronized (RequestHandler.class) {
- created++;
- if ((created % 50) == 0) {
- System.out.println(".");
- created = 0;
- } else {
- System.out.print(".");
- }
- }
- }
-
- // Returns true when request is complete
- // May expand rbb if more room required
- //
- private boolean receive(SelectionKey sk) throws IOException {
- ByteBuffer tmp = null;
-
- if (requestReceived) {
- return true;
- }
-
- if (!cio.doHandshake(sk)) {
- return false;
- }
-
- if ((cio.read() < 0) || Request.isComplete(cio.getReadBuf())) {
- rbb = cio.getReadBuf();
- return (requestReceived = true);
- }
- return false;
- }
-
- // When parse is successfull, saves request and returns true
- //
- private boolean parse() throws IOException {
- try {
- request = Request.parse(rbb);
- return true;
- } catch (MalformedRequestException x) {
- reply = new Reply(Reply.Code.BAD_REQUEST,
- new StringContent(x));
- }
- return false;
- }
-
- // Ensures that reply field is non-null
- //
- private void build() throws IOException {
- Request.Action action = request.action();
- if ((action != Request.Action.GET) &&
- (action != Request.Action.HEAD)) {
- reply = new Reply(Reply.Code.METHOD_NOT_ALLOWED,
- new StringContent(request.toString()));
- }
- reply = new Reply(Reply.Code.OK,
- new FileContent(request.uri()), action);
- }
-
- public void handle(SelectionKey sk) throws IOException {
- try {
-
- if (request == null) {
- if (!receive(sk))
- return;
- rbb.flip();
- if (parse())
- build();
- try {
- reply.prepare();
- } catch (IOException x) {
- reply.release();
- reply = new Reply(Reply.Code.NOT_FOUND,
- new StringContent(x));
- reply.prepare();
- }
- if (send()) {
- // More bytes remain to be written
- sk.interestOps(SelectionKey.OP_WRITE);
- } else {
- // Reply completely written; we're done
- if (cio.shutdown()) {
- cio.close();
- reply.release();
- }
- }
- } else {
- if (!send()) { // Should be rp.send()
- if (cio.shutdown()) {
- cio.close();
- reply.release();
- }
- }
- }
- } catch (IOException x) {
- String m = x.getMessage();
- if (!m.equals("Broken pipe") &&
- !m.equals("Connection reset by peer")) {
- System.err.println("RequestHandler: " + x.toString());
- }
-
- try {
- /*
- * We had a failure here, so we'll try to be nice
- * before closing down and send off a close_notify,
- * but if we can't get the message off with one try,
- * we'll just shutdown.
- */
- cio.shutdown();
- } catch (IOException e) {
- // ignore
- }
-
- cio.close();
- if (reply != null) {
- reply.release();
- }
- }
-
- }
-
- private boolean send() throws IOException {
- try {
- return reply.send(cio);
- } catch (IOException x) {
- if (x.getMessage().startsWith("Resource temporarily")) {
- System.err.println("## RTA");
- return true;
- }
- throw x;
- }
- }
-}
diff --git a/jdk/src/sample/share/nio/server/RequestServicer.java b/jdk/src/sample/share/nio/server/RequestServicer.java
deleted file mode 100644
index 88d40b5d57c..00000000000
--- a/jdk/src/sample/share/nio/server/RequestServicer.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-
-import java.io.*;
-import java.nio.*;
-
-/**
- * Primary driver class used by blocking Servers to receive,
- * prepare, send, and shutdown requests.
- *
- * @author Mark Reinhold
- * @author Brad R. Wetmore
- */
-class RequestServicer implements Runnable {
-
- private ChannelIO cio;
-
- private static int created = 0;
-
- RequestServicer(ChannelIO cio) {
- this.cio = cio;
-
- // Simple heartbeat to let user know we're alive.
- synchronized (RequestServicer.class) {
- created++;
- if ((created % 50) == 0) {
- System.out.println(".");
- created = 0;
- } else {
- System.out.print(".");
- }
- }
- }
-
- private void service() throws IOException {
- Reply rp = null;
- try {
- ByteBuffer rbb = receive(); // Receive
- Request rq = null;
- try { // Parse
- rq = Request.parse(rbb);
- } catch (MalformedRequestException x) {
- rp = new Reply(Reply.Code.BAD_REQUEST,
- new StringContent(x));
- }
- if (rp == null) rp = build(rq); // Build
- do {} while (rp.send(cio)); // Send
- do {} while (!cio.shutdown());
- cio.close();
- rp.release();
- } catch (IOException x) {
- String m = x.getMessage();
- if (!m.equals("Broken pipe") &&
- !m.equals("Connection reset by peer")) {
- System.err.println("RequestHandler: " + x.toString());
- }
-
- try {
- /*
- * We had a failure here, so we'll try to be nice
- * before closing down and send off a close_notify,
- * but if we can't get the message off with one try,
- * we'll just shutdown.
- */
- cio.shutdown();
- } catch (IOException e) {
- // ignore
- }
-
- cio.close();
- if (rp != null) {
- rp.release();
- }
- }
- }
-
- public void run() {
- try {
- service();
- } catch (IOException x) {
- x.printStackTrace();
- }
- }
-
- ByteBuffer receive() throws IOException {
-
- do {} while (!cio.doHandshake());
-
- for (;;) {
- int read = cio.read();
- ByteBuffer bb = cio.getReadBuf();
- if ((read < 0) || (Request.isComplete(bb))) {
- bb.flip();
- return bb;
- }
- }
- }
-
- Reply build(Request rq) throws IOException {
-
- Reply rp = null;
- Request.Action action = rq.action();
- if ((action != Request.Action.GET) &&
- (action != Request.Action.HEAD))
- rp = new Reply(Reply.Code.METHOD_NOT_ALLOWED,
- new StringContent(rq.toString()));
- else
- rp = new Reply(Reply.Code.OK,
- new FileContent(rq.uri()), action);
- try {
- rp.prepare();
- } catch (IOException x) {
- rp.release();
- rp = new Reply(Reply.Code.NOT_FOUND,
- new StringContent(x));
- rp.prepare();
- }
- return rp;
- }
-}
diff --git a/jdk/src/sample/share/nio/server/Sendable.java b/jdk/src/sample/share/nio/server/Sendable.java
deleted file mode 100644
index 44ac84826ae..00000000000
--- a/jdk/src/sample/share/nio/server/Sendable.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-
-import java.io.*;
-
-/**
- * Method definitions used for preparing, sending, and release
- * content.
- *
- * @author Mark Reinhold
- * @author Brad R. Wetmore
- */
-interface Sendable {
-
- void prepare() throws IOException;
-
- // Sends (some) content to the given channel.
- // Returns true if more bytes remain to be written.
- // Throws IllegalStateException if not prepared.
- //
- boolean send(ChannelIO cio) throws IOException;
-
- void release() throws IOException;
-}
diff --git a/jdk/src/sample/share/nio/server/Server.java b/jdk/src/sample/share/nio/server/Server.java
deleted file mode 100644
index 1ac64213b33..00000000000
--- a/jdk/src/sample/share/nio/server/Server.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-
-import java.io.*;
-import java.net.*;
-import java.nio.channels.*;
-import java.security.*;
-import javax.net.ssl.*;
-
-/**
- * The main server base class.
- *
- * This class is responsible for setting up most of the server state
- * before the actual server subclasses take over.
- *
- * @author Mark Reinhold
- * @author Brad R. Wetmore
- */
-public abstract class Server {
-
- ServerSocketChannel ssc;
- SSLContext sslContext = null;
-
- static private int PORT = 8000;
- static private int BACKLOG = 1024;
- static private boolean SECURE = false;
-
- Server(int port, int backlog,
- boolean secure) throws Exception {
-
- if (secure) {
- createSSLContext();
- }
-
- ssc = ServerSocketChannel.open();
- ssc.socket().setReuseAddress(true);
- ssc.socket().bind(new InetSocketAddress(port), backlog);
- }
-
- /*
- * If this is a secure server, we now setup the SSLContext we'll
- * use for creating the SSLEngines throughout the lifetime of
- * this process.
- */
- private void createSSLContext() throws Exception {
-
- char[] passphrase = "passphrase".toCharArray();
-
- KeyStore ks = KeyStore.getInstance("JKS");
- ks.load(new FileInputStream("testkeys"), passphrase);
-
- KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
- kmf.init(ks, passphrase);
-
- TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
- tmf.init(ks);
-
- sslContext = SSLContext.getInstance("TLS");
- sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
- }
-
- abstract void runServer() throws Exception;
-
- static private void usage() {
- System.out.println(
- "Usage: Server
- * Any type of URL can be used: http, https, ftp, etc.
- *
- * @author Brad R. Wetmore
- * @author Mark Reinhold
- */
-public class URLDumper {
- public static void main(String[] args) throws Exception {
-
- if (args.length != 2) {
- System.out.println("Usage: URLDumper
- This demo shows how to use the try-with-resources feature introduced in JDK7.
-
- Shows how to use a custom resource with the try-with-resources construct.
- For more information, see the source file.
-
- Extracts archived files. For more information, see the source file.
- Prints data about a specified file from an archive. For more information, see the source file.ResultLogManagerMXBean can be configured to log
- * these records to a flat file, or into a log held in memory, or both.
- * Both logs (file and memory) can be configured with a maximum capacity.
- *
When the maximum capacity of the memory log is reached - its first
- * entry (i.e. its eldest entry) is removed to make place for the latest.
- *
When the maximum capacity of the file log is reached, the file is
- * renamed by appending a tilde '~' to its name and a new result log is created.
- *
- *
- * @author Sun Microsystems, 2006 - All rights reserved.
- */
-public class ResultLogManager extends NotificationBroadcasterSupport
- implements ResultLogManagerMXBean, MBeanRegistration {
-
- /**
- * The default singleton name of the {@link ResultLogManagerMXBean}.
- **/
- public static final ObjectName RESULT_LOG_MANAGER_NAME =
- ScanManager.makeSingletonName(ResultLogManagerMXBean.class);
-
- /**
- * A logger for this class.
- **/
- private static final Logger LOG =
- Logger.getLogger(ResultLogManager.class.getName());
-
- // The memory log
- //
- private final ListResultLogManager.
- **/
- ResultLogManager() {
- // Instantiate the memory log - override the add() method so that
- // it removes the head of the list when the maximum capacity is
- // reached. Note that add() is the only method we will be calling,
- // otherwise we would have to override all the other flavors
- // of adding methods. Note also that this implies that the memoryLog
- // will *always* remain encapsulated in this object and is *never*
- // handed over (otherwise we wouldn't be able to ensure that
- // add() is the only method ever called to add a record).
- //
- memoryLog =
- Collections.synchronizedList(new LinkedList
- * com.sun.jmx.examples.scandir.log.file.switched
- * com.sun.jmx.examples.scandir.log.memory.full
- * com.sun.jmx.examples.scandir.log.memory.cleared
- *
- **/
- public MBeanNotificationInfo[] getNotificationInfo() {
- return new MBeanNotificationInfo[] {
- new MBeanNotificationInfo(new String[] {
- LOG_FILE_CHANGED},
- Notification.class.getName(),
- "Emitted when the log file is switched")
- ,
- new MBeanNotificationInfo(new String[] {
- MEMORY_LOG_MAX_CAPACITY},
- Notification.class.getName(),
- "Emitted when the memory log capacity is reached")
- ,
- new MBeanNotificationInfo(new String[] {
- MEMORY_LOG_CLEARED},
- Notification.class.getName(),
- "Emitted when the memory log is cleared")
- };
- }
-
- // Return the name of the log file, or null if logging to file is
- // disabled.
- private String getLogFileName(boolean absolute) {
- synchronized (this) {
- if (logFile == null) return null;
- if (absolute) return logFile.getAbsolutePath();
- return logFile.getPath();
- }
- }
-
- // This method is be called by the ScanManagerMXBean when a configuration
- // is applied.
- //
- void setConfig(ResultLogConfig logConfigBean) throws IOException {
- if (logConfigBean == null)
- throw new IllegalArgumentException("logConfigBean is null");
- synchronized (this) {
- config = logConfigBean;
- setMemoryLogCapacity(config.getMemoryMaxRecords());
- }
- final String filename = config.getLogFileName();
- final String logname = getLogFileName(false);
- if ((filename != null && !filename.equals(logname))
- || (filename == null && logname != null)) {
- newLogFile(config.getLogFileName(),
- config.getLogFileMaxRecords());
- } else {
- setLogFileCapacity(config.getLogFileMaxRecords());
- }
- }
-
- // This method is called by the ScanManagerMXBean when
- // applyCurrentResultLogConfig() is called.
- //
- ResultLogConfig getConfig() {
- return config;
- }
-
-
- // Set by preRegister().
- private MBeanServer mbeanServer;
- private ObjectName objectName;
-
-
-
-}
diff --git a/jdk/src/sample/share/jmx/jmx-scandir/src/com/sun/jmx/examples/scandir/ResultLogManagerMXBean.java b/jdk/src/sample/share/jmx/jmx-scandir/src/com/sun/jmx/examples/scandir/ResultLogManagerMXBean.java
deleted file mode 100644
index eb1f0f6a4f1..00000000000
--- a/jdk/src/sample/share/jmx/jmx-scandir/src/com/sun/jmx/examples/scandir/ResultLogManagerMXBean.java
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-
-package com.sun.jmx.examples.scandir;
-
-import com.sun.jmx.examples.scandir.config.ResultRecord;
-import java.io.IOException;
-import javax.management.InstanceNotFoundException;
-
-/**
- * The ResultLogManagerMXBean is in charge of managing result logs.
- * {@link DirectoryScanner DirectoryScanners} can be configured to log a
- * {@link ResultRecord} whenever they take action upon a file that
- * matches their set of matching criteria.
- * The ResultLogManagerMXBean is responsible for storing these
- * results in its result logs.
- * ResultLogManagerMXBean
- * will let you interactively clear these result logs, change their
- * capacity, and decide where (memory or file or both) the
- * {@link ResultRecord ResultRecords} should be stored.
- * ResultLogManagerMXBean.
- * The file log doesn't have this facility.
- * null means that no log file is configured: logging
- * to file is disabled.
- * null
- * if logging to file is disabled.
- * @throws IOException A connection problem occurred when accessing
- * the underlying resource.
- * @throws InstanceNotFoundException The underlying MBean is not
- * registered in the MBeanServer.
- **/
- public String getLogFileName()
- throws IOException, InstanceNotFoundException;
-
- /**
- * Gets the whole content of the memory log. This cannot exceed
- * {@link #getMemoryLogCapacity} records.
- *
- * @return the whole content of the memory log.
- * @throws IOException A connection problem occurred when accessing
- * the underlying resource.
- * @throws InstanceNotFoundException The underlying MBean is not
- * registered in the MBeanServer.
- **/
- public ResultRecord[] getMemoryLog()
- throws IOException, InstanceNotFoundException;
-
- /**
- * Gets the maximum number of records that can be logged in the
- * memory log.
- * 0 or negative - means that
- * logging in memory is disabled.
- * 0 or negative - means that
- * logging in memory is disabled. It will also have the side
- * effect of clearing the memory log.
- * ScanDirAgent is the Agent class for the scandir
- * application.
- * This class contains the {@link #main} method to start a standalone
- * scandir application.
- *
- * Therefore we don't need to concern ourselves with the possibility of
- * missing the window in which the ScanManagerMXBean state's will be
- * CLOSED, because that particular window stays opened forever.
- * System.out.
- *
- **/
- public static void main(String[] args) {
- try {
- // Check args
- //
- if (args==null || args.length!=2) {
- System.err.println("Bad number of arguments: usage is: \n\t" +
- USAGE);
- System.exit(1);
- }
- try {
- InetAddress.getByName(args[0]);
- } catch (UnknownHostException x) {
- System.err.println("No such host: " + args[0]+
- "\n usage is: \n\t" + USAGE);
- System.exit(2);
- } catch (Exception x) {
- System.err.println("Bad address: " + args[0]+
- "\n usage is: \n\t" + USAGE);
- System.exit(2);
- }
- try {
- if (Integer.parseInt(args[1]) <= 0) {
- System.err.println("Bad port value: " + args[1]+
- "\n usage is: \n\t" + USAGE);
- System.exit(2);
- }
- } catch (Exception x) {
- System.err.println("Bad argument: " + args[1]+
- "\n usage is: \n\t" + USAGE);
- System.exit(2);
- }
-
- // Create an environment map to hold connection properties
- // like credentials etc... We will later pass this map
- // to the JMX Connector.
- //
- System.out.println("\nInitialize the environment map");
- final Map
ScanDirConfig MBean is in charge of the
- * scandir application configuration.
- * ScanDirConfig MBean is able to
- * load and save the scandir application configuration to and from an
- * XML file.
- * ScanDirConfigMXBean registered
- * in the MBeanServer as you like, but only one of them will be identified as
- * the current configuration of the {@link ScanManagerMXBean}.
- * You can switch to another configuration by calling {@link
- * ScanManagerMXBean#setConfigurationMBean
- * ScanManagerMXBean.setConfigurationMBean}.
- * true means that we apply the configuration from memory,
- * without first reloading the file.
- * ScanDirConfig uses the XML annotated Java Beans defined
- * in the {@link com.sun.jmx.examples.scandir.config} package.
- * ScanDirConfig should probably use
- * {@code java.nio.channels.FileLock} and lock its configuration file so that
- * two ScanDirConfig object do not share the same file, but it
- * doesn't. Feel free to improve the application in that way.
- * ScanDirConfigMXBean is in charge of the
- * scandir application configuration.
- * ScanDirConfigMXBean is an MBean which is able to
- * load and save the scandir application configuration to and from an
- * XML file.
- * ScanDirConfigMXBean registered
- * in the MBeanServer as you like, but only one of them will be identified as
- * the current configuration of the {@link ScanManagerMXBean}.
- * You can switch to another configuration by calling {@link
- * ScanManagerMXBean#setConfigurationMBean
- * ScanManagerMXBean.setConfigurationMBean}.
- * true means that we apply the configuration from memory,
- * without first reloading the file.
- * name= key.
- * @param dir The root directory at which this scanner will start scanning.
- * @param filePattern A {@link java.util.regex.Pattern regular expression}
- * to match against a selected file name.
- * @param sizeExceedsMaxBytes Only file whose size exceeds that limit will
- * be selected. 0 or a
- * negative value is provided.
- * @see #getSaveState()
- * @return The added DirectoryScannerConfig.
- * @throws IOException A connection problem occurred when accessing
- * the underlying resource.
- * @throws InstanceNotFoundException The underlying MBean is not
- * registered in the MBeanServer.
- **/
- public DirectoryScannerConfig
- addDirectoryScanner(String name, String dir, String filePattern,
- long sizeExceedsMaxBytes, long sinceLastModified)
- throws IOException, InstanceNotFoundException;
-
- /**
- * Removes a directory scanner from the current configuration data.
- * name= key.
- * @return The removed DirectoryScannerConfig.
- * @throws IllegalArgumentException if there's no directory scanner by
- * that name in the current configuration data.
- * @throws IOException A connection problem occurred when accessing
- * the underlying resource.
- * @throws InstanceNotFoundException The underlying MBean is not
- * registered in the MBeanServer.
- **/
- public DirectoryScannerConfig
- removeDirectoryScanner(String name)
- throws IOException, InstanceNotFoundException;
-
- /**
- * Gets the save state of the current configuration data.
- * ScanManager is responsible for applying a configuration,
- * starting and scheduling directory scans, and reporting application state.
- * ScanManager MBean is the entry point of the scandir
- * application management interface. It is from this MBean that all other MBeans
- * will be created and registered.
- * type= and
- * name= for an instance of a given MBean interface class.
- * @param clazz The interface class of the MBean for which we want to obtain
- * a default name, or its implementation class.
- * Give one or the other depending on what you wish to see in
- * the value of the key {@code type=}.
- * @param name The value of the name= key.
- * @return A default name for an instance of the given MBean interface class.
- * @throws IllegalArgumentException if the name can't be created.
- * (e.g. an unexpected exception was raised).
- **/
- public static final ObjectName makeMBeanName(Class clazz, String name) {
- try {
- return ObjectName.
- getInstance(makeSingletonName(clazz)
- .toString()+",name="+name);
- } catch (MalformedObjectNameException x) {
- final IllegalArgumentException iae =
- new IllegalArgumentException(String.valueOf(name),x);
- throw iae;
- }
- }
-
- /**
- * Return the ObjectName for a DirectoryScannerMXBean of that name.
- * This is {@code makeMBeanName(DirectoryScannerMXBean.class,name)}.
- * @param name The value of the name= key.
- * @return the ObjectName for a DirectoryScannerMXBean of that name.
- */
- public static final ObjectName makeDirectoryScannerName(String name) {
- return makeMBeanName(DirectoryScannerMXBean.class,name);
- }
-
- /**
- * Return the ObjectName for a {@code ScanDirConfigMXBean} of that name.
- * This is {@code makeMBeanName(ScanDirConfigMXBean.class,name)}.
- * @param name The value of the name= key.
- * @return the ObjectName for a {@code ScanDirConfigMXBean} of that name.
- */
- public static final ObjectName makeScanDirConfigName(String name) {
- return makeMBeanName(ScanDirConfigMXBean.class,name);
- }
-
- /**
- * Create and register a new singleton instance of the ScanManager
- * MBean in the given {@link MBeanServerConnection}.
- * @param mbs The MBeanServer in which the new singleton instance
- * should be created.
- * @throws JMException The MBeanServer connection raised an exception
- * while trying to instantiate and register the singleton MBean
- * instance.
- * @throws IOException There was a connection problem while trying to
- * communicate with the underlying MBeanServer.
- * @return A proxy for the registered MBean.
- **/
- public static ScanManagerMXBean register(MBeanServerConnection mbs)
- throws IOException, JMException {
- final ObjectInstance moi =
- mbs.createMBean(ScanManager.class.getName(),SCAN_MANAGER_NAME);
- final ScanManagerMXBean proxy =
- JMX.newMXBeanProxy(mbs,moi.getObjectName(),
- ScanManagerMXBean.class,true);
- return proxy;
- }
-
- /**
- * Creates a new {@code ScanManagerMXBean} proxy over the given
- * {@code MBeanServerConnection}. Does not check whether a
- * {@code ScanManagerMXBean}
- * is actually registered in that {@code MBeanServerConnection}.
- * @return a new {@code ScanManagerMXBean} proxy.
- * @param mbs The {@code MBeanServerConnection} which holds the
- * {@code ScanManagerMXBean} to proxy.
- */
- public static ScanManagerMXBean
- newSingletonProxy(MBeanServerConnection mbs) {
- final ScanManagerMXBean proxy =
- JMX.newMXBeanProxy(mbs,SCAN_MANAGER_NAME,
- ScanManagerMXBean.class,true);
- return proxy;
- }
-
- /**
- * Creates a new {@code ScanManagerMXBean} proxy over the platform
- * {@code MBeanServer}. This is equivalent to
- * {@code newSingletonProxy(ManagementFactory.getPlatformMBeanServer())}.
- * @return a new {@code ScanManagerMXBean} proxy.
- **/
- public static ScanManagerMXBean newSingletonProxy() {
- return newSingletonProxy(ManagementFactory.getPlatformMBeanServer());
- }
-
- /**
- * Create and register a new singleton instance of the ScanManager
- * MBean in the given {@link MBeanServerConnection}.
- * @throws JMException The MBeanServer connection raised an exception
- * while trying to instantiate and register the singleton MBean
- * instance.
- * @throws IOException There was a connection problem while trying to
- * communicate with the underlying MBeanServer.
- * @return A proxy for the registered MBean.
- **/
- public static ScanManagerMXBean register()
- throws IOException, JMException {
- final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
- return register(mbs);
- }
-
- /**
- * Create a new ScanManager MBean
- **/
- public ScanManager() {
- broadcaster = new NotificationBroadcasterSupport();
- pendingNotifs = new LinkedBlockingQueueScanManagerMXBean is responsible for applying a
- * configuration, starting and scheduling directory scans, and reporting
- * application state.
- * ScanManagerMXBean is a singleton MBean: there can be
- * at most one instance of such an MBean registered in a given MBeanServer.
- * The name of that MBean is a constant defined in
- * {@link ScanManager#SCAN_MANAGER_NAME ScanManager.SCAN_MANAGER_NAME}.
- * ScanManagerMXBean is the entry point of the scandir
- * application management interface. It is from this MBean that all other
- * MBeans will be created and registered.
- * name= key
- * of the {@link DirectoryScannerMXBean} ObjectName.
- * @throws IOException A connection problem occurred when accessing
- * the underlying resource.
- * @throws JMException The MBeanServer failed to call the underlying MBean.
- **/
- public MapResultLogManagerMXBean
- * current configuration from being reset when {@link #applyConfiguration
- * applyConfiguration} is called.
- * @param toMemory if {@code true} only replaces the initial result log
- * configuration held in memory.
- * if {@code false}, the {@link
- * #getConfigurationMBean configuration MBean} will be asked to commit
- * the whole configuration to the configuration file.
- *
- * @throws IOException A connection problem occurred when accessing
- * the underlying resource.
- * @throws JMException The MBeanServer failed to call the underlying MBean.
- **/
- public void applyCurrentResultLogConfig(boolean toMemory)
- throws IOException, JMException;
-
- /**
- * Instruct the {@code ScanManagerMXBean} to use another {@link
- * ScanDirConfigMXBean configuration MBean}.
- * name= key
- * of the new {@link ScanDirConfigMXBean}.
- * @param filename The path of the file from which the new {@link
- * ScanDirConfigMXBean} can {@link ScanDirConfigMXBean#load load} or
- * {@link ScanDirConfigMXBean#save save} its configuration data.
- * Note that even if the file exists and contain a valid
- * configuration, you will still need to call {@link
- * ScanDirConfigMXBean#load load} to make the {@link
- * ScanDirConfigMXBean} load its configuration data.
- * @throws IOException A connection problem occurred when accessing
- * the underlying resource.
- * @throws JMException The MBeanServer failed to call the underlying MBean.
- * @return A proxy to the created {@link ScanDirConfigMXBean}.
- */
- public ScanDirConfigMXBean createOtherConfigurationMBean(String name,
- String filename)
- throws JMException, IOException;
-}
diff --git a/jdk/src/sample/share/jmx/jmx-scandir/src/com/sun/jmx/examples/scandir/config/DirectoryScannerConfig.java b/jdk/src/sample/share/jmx/jmx-scandir/src/com/sun/jmx/examples/scandir/config/DirectoryScannerConfig.java
deleted file mode 100644
index b3f8e9ff6f4..00000000000
--- a/jdk/src/sample/share/jmx/jmx-scandir/src/com/sun/jmx/examples/scandir/config/DirectoryScannerConfig.java
+++ /dev/null
@@ -1,392 +0,0 @@
-/*
- * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-
-package com.sun.jmx.examples.scandir.config;
-
-import java.io.File;
-import java.io.FileFilter;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.logging.Logger;
-import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlElementRef;
-import javax.xml.bind.annotation.XmlElementWrapper;
-import javax.xml.bind.annotation.XmlList;
-import javax.xml.bind.annotation.XmlRootElement;
-
-/**
- * The DirectoryScannerConfig Java Bean is used to model
- * the configuration of a {@link
- * com.sun.jmx.examples.scandir.DirectoryScannerMXBean}.
- * FileMatch Java Bean is used to model
- * the configuration of a {@link FileFilter} which
- * matches {@link File files} against a set of criteria.
- * FileMatch class also implements
- * {@link FileFilter} - applying an {@code AND} on all
- * its conditions. {@code OR} conditions can be obtained
- * by supplying several instances of FileMatch
- * to the encapsulating {@link DirectoryScannerConfig}, which
- * respectively applies an {@code OR} on all its
- * {@code
- * If File.isDirectory() && directoryPattern!=null &&
- * File.getName().matches(directoryPattern)==false,
- * then File doesn't match this filter.
- *
This condition is ignored if {@code lastModifiedAfter} is
- * {@code null}.
- * @return Value of property {@code lastModifiedAfter}.
- */
- @XmlElement(name="LastModifiedAfter",namespace=XmlConfigUtils.NAMESPACE)
- public Date getLastModifiedAfter() {
- return (lastModifiedAfter==null)?null:(Date)lastModifiedAfter.clone();
- }
-
- /**
- * Setter for property {@code lastModifiedAfter}.
- * @param lastModifiedAfter A file will be selected only if it was
- * last modified after {@code lastModifiedAfter}.
- *
This condition is ignored if {@code lastModifiedAfter} is
- * {@code null}.
- */
- public void setLastModifiedAfter(Date lastModifiedAfter) {
- this.lastModifiedAfter =
- (lastModifiedAfter==null)?null:(Date)lastModifiedAfter.clone();
- }
-
- /**
- * Getter for property {@code lastModifiedBefore}.
- * A file will be selected only if it was last modified before
- * {@code lastModifiedBefore}.
- *
This condition is ignored if {@code lastModifiedBefore} is
- * {@code null}.
- * @return Value of property {@code lastModifiedBefore}.
- */
- @XmlElement(name="LastModifiedBefore",namespace=XmlConfigUtils.NAMESPACE)
- public Date getLastModifiedBefore() {
- return (lastModifiedBefore==null)?null:(Date)lastModifiedBefore.clone();
- }
-
- /**
- * Setter for property {@code lastModifiedBefore}.
- * @param lastModifiedBefore A file will be selected only if it was
- * last modified before {@code lastModifiedBefore}.
- *
This condition is ignored if {@code lastModifiedBefore} is
- * {@code null}.
- */
- public void setLastModifiedBefore(Date lastModifiedBefore) {
- this.lastModifiedBefore =
- (lastModifiedBefore==null)?null:(Date)lastModifiedBefore.clone();
- }
-
- // Accepts or rejects a file with regards to the values of the fields
- // configured in this bean. The accept() method is the implementation
- // of FileFilter.accept(File);
- //
- /**
- * A file is accepted when all the criteria that have been set
- * are matched.
- * @param f The file to match against the configured criteria.
- * @return {@code true} if the file matches all criteria,
- * {@code false} otherwise.
- */
- public boolean accept(File f) {
-
- // Directories are accepted if they match against the directory pattern.
- //
- if (f.isDirectory()) {
- if (directoryPattern != null
- && !f.getName().matches(directoryPattern))
- return false;
- else return true;
- }
-
- // If we reach here, the f is not a directory.
- //
- // Files are accepted if they match all other conditions.
-
- // Check whether f matches filePattern
- if (filePattern != null
- && !f.getName().matches(filePattern))
- return false;
-
- // Check whether f exceeeds size limit
- if (sizeExceedsMaxBytes > 0 && f.length() <= sizeExceedsMaxBytes)
- return false;
-
- // Check whether f was last modified after lastModifiedAfter
- if (lastModifiedAfter != null &&
- lastModifiedAfter.after(new Date(f.lastModified())))
- return false;
-
- // Check whether f was last modified before lastModifiedBefore
- if (lastModifiedBefore != null &&
- lastModifiedBefore.before(new Date(f.lastModified())))
- return false;
-
- // All conditions were met: accept file.
- return true;
- }
-
- // used by equals()
- private Object[] toArray() {
- final Object[] thisconfig = {
- directoryPattern, filePattern, lastModifiedAfter,
- lastModifiedBefore, sizeExceedsMaxBytes
- };
- return thisconfig;
- }
-
- @Override
- public boolean equals(Object o) {
- if (o == this) return true;
- if (!(o instanceof FileMatch)) return false;
- final FileMatch other = (FileMatch)o;
- final Object[] thisconfig = toArray();
- final Object[] otherconfig = other.toArray();
- return Arrays.deepEquals(thisconfig,otherconfig);
- }
-
- @Override
- public int hashCode() {
- return Arrays.deepHashCode(toArray());
- }
-
-}
diff --git a/jdk/src/sample/share/jmx/jmx-scandir/src/com/sun/jmx/examples/scandir/config/ResultLogConfig.java b/jdk/src/sample/share/jmx/jmx-scandir/src/com/sun/jmx/examples/scandir/config/ResultLogConfig.java
deleted file mode 100644
index 5f3d668c359..00000000000
--- a/jdk/src/sample/share/jmx/jmx-scandir/src/com/sun/jmx/examples/scandir/config/ResultLogConfig.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-
-package com.sun.jmx.examples.scandir.config;
-
-import java.util.Arrays;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-
-/**
- * The ResultLogConfig Java Bean is used to model
- * the initial configuration of the {@link
- * com.sun.jmx.examples.scandir.ResultLogManagerMXBean}.
- *
- * ResultRecord Java Bean is used to write the
- * results of a directory scan to a result log.
- *
- * ScanManagerConfig Java Bean is used to model
- * the configuration of the {@link
- * com.sun.jmx.examples.scandir.ScanManagerMXBean ScanManagerMXBean}.
- *
- * The {@link
- * com.sun.jmx.examples.scandir.ScanManagerMXBean ScanManagerMXBean} will
- * use this configuration to initialize the {@link
- * com.sun.jmx.examples.scandir.ResultLogManagerMXBean ResultLogManagerMXBean}
- * and create the {@link
- * com.sun.jmx.examples.scandir.DirectoryScannerMXBean DirectoryScannerMXBeans}
- * Bulk Data Operations Demo
-
-
-
-
-
diff --git a/jdk/src/sample/share/lambda/BulkDataOperations/src/CSVProcessor.java b/jdk/src/sample/share/lambda/BulkDataOperations/src/CSVProcessor.java
deleted file mode 100644
index ded9030209d..00000000000
--- a/jdk/src/sample/share/lambda/BulkDataOperations/src/CSVProcessor.java
+++ /dev/null
@@ -1,368 +0,0 @@
-/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation, and proper error handling, might not be present in
- * this sample code.
- */
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.util.*;
-import java.util.function.*;
-import java.util.regex.Pattern;
-import java.util.stream.Collector;
-import java.util.stream.Collectors;
-
-import static java.lang.Double.parseDouble;
-import static java.util.stream.Collectors.*;
-
-/**
- * CSVProcessor is a tool for processing CSV files. There are several
- * command-line options. Consult the {@link #printUsageAndExit} method for
- * instructions and command line parameters. This sample shows examples of the
- * following features:
- * CSV Processor
-
- Grep
-
- PasswordGenerator
-
- WC
-
-
- *
- *
- */
-public class CSVProcessor {
-
- //Number of characters that may be read
- private static final int READ_AHEAD_LIMIT = 100_000_000;
-
- /**
- * The main method for the CSVProcessor program. Run the program with an
- * empty argument list to see possible arguments.
- *
- * @param args the argument list for CSVProcessor.
- */
- public static void main(String[] args) {
- if (args.length < 2) {
- printUsageAndExit();
- }
- try (BufferedReader br = new BufferedReader(
- Files.newBufferedReader(Paths.get(args[args.length - 1])))) {
- //Assume that the first line contains column names.
- List
- *
- *
- */
-public class Grep {
-
- private static void printUsageAndExit(String... str) {
- System.out.println("Usage: " + Grep.class.getSimpleName()
- + " [OPTION]... PATTERN FILE...");
- System.out.println("Search for PATTERN in each FILE. "
- + "If FILE is a directory then whole file tree of the directory"
- + " will be processed.");
- System.out.println("Example: grep -m 100 'hello world' menu.h main.c");
- System.out.println("Options:");
- System.out.println(" -m NUM: stop analysis after NUM matches");
- Arrays.asList(str).forEach(System.err::println);
- System.exit(1);
- }
-
- /**
- * The main method for the Grep program. Run program with empty argument
- * list to see possible arguments.
- *
- * @param args the argument list for Grep.
- * @throws java.io.IOException If an I/O error occurs.
- */
- public static void main(String[] args) throws IOException {
- long maxCount = Long.MAX_VALUE;
- if (args.length < 2) {
- printUsageAndExit();
- }
- int i = 0;
- //parse OPTIONS
- while (args[i].startsWith("-")) {
- switch (args[i]) {
- case "-m":
- try {
- maxCount = Long.parseLong(args[++i]);
- } catch (NumberFormatException ex) {
- printUsageAndExit(ex.toString());
- }
- break;
- default:
- printUsageAndExit("Unexpected option " + args[i]);
- }
- i++;
- }
- //parse PATTERN
- Pattern pattern = Pattern.compile(args[i++]);
- if (i == args.length) {
- printUsageAndExit("There are no files for input");
- }
-
- try {
- /*
- * First obtain the list of all paths.
- * For a small number of arguments there is little to be gained
- * by producing this list in parallel. For one argument
- * there will be no parallelism.
- *
- * File names are converted to paths. If a path is a directory then
- * Stream is populated with whole file tree of the directory by
- * flatMap() method. Files are filtered from directories.
- */
- List
- *
- *
- */
-public class PasswordGenerator {
-
- private static void usage() {
- System.out.println("Usage: PasswordGenerator LENGTH");
- System.out.println(
- "Password Generator produces password of desired LENGTH.");
- }
-
- private static final List
- *
- *
- */
-public class WC {
-
- //The number of characters that may be read.
- private static final int READ_AHEAD_LIMIT = 100_000_000;
-
- //The pattern for splitting strings by non word characters to get words.
- private static final Pattern nonWordPattern = Pattern.compile("\\W");
-
- /**
- * The main method for the WC program. Run the program with an empty
- * argument list to see possible arguments.
- *
- * @param args the argument list for WC
- * @throws java.io.IOException If an input exception occurred.
- */
- public static void main(String[] args) throws IOException {
-
- if (args.length != 1) {
- usage();
- return;
- }
-
- try (BufferedReader reader = new BufferedReader(
- new FileReader(args[0]))) {
- reader.mark(READ_AHEAD_LIMIT);
- /*
- * Statistics can be gathered in four passes using a built-in API.
- * The method demonstrates how separate operations can be
- * implemented using a built-in API.
- */
- collectInFourPasses(reader);
- /*
- * Usage of several passes to collect data is not the best way.
- * Statistics can be gathered by a custom collector in one pass.
- */
- reader.reset();
- collectInOnePass(reader);
- } catch (FileNotFoundException e) {
- usage();
- System.err.println(e);
- }
- }
-
- private static void collectInFourPasses(BufferedReader reader)
- throws IOException {
- /*
- * Input is read as a stream of lines by lines().
- * Every line is turned into a stream of chars by the flatMapToInt(...)
- * method.
- * Length of the stream is counted by count().
- */
- System.out.println("Character count = "
- + reader.lines().flatMapToInt(String::chars).count());
- /*
- * Input is read as a stream of lines by lines().
- * Every line is split by nonWordPattern into words by flatMap(...)
- * method.
- * Empty lines are removed by the filter(...) method.
- * Length of the stream is counted by count().
- */
- reader.reset();
- System.out.println("Word count = "
- + reader.lines()
- .flatMap(nonWordPattern::splitAsStream)
- .filter(str -> !str.isEmpty()).count());
-
- reader.reset();
- System.out.println("Newline count = " + reader.lines().count());
- /*
- * Input is read as a stream of lines by lines().
- * Every line is mapped to its length.
- * Maximum of the lengths is calculated.
- */
- reader.reset();
- System.out.println("Max line length = "
- + reader.lines().mapToInt(String::length).max().getAsInt());
- }
-
- private static void collectInOnePass(BufferedReader reader) {
- /*
- * The collect() method has three parameters:
- * The first parameter is the {@code WCStatistic} constructor reference.
- * collect() will create {@code WCStatistics} instances, where
- * statistics will be aggregated.
- * The second parameter shows how {@code WCStatistics} will process
- * String.
- * The third parameter shows how to merge two {@code WCStatistic}
- * instances.
- *
- * Also {@code Collector} can be used, which would be more reusable
- * solution. See {@code CSVProcessor} example for how {@code Collector}
- * can be implemented.
- *
- * Note that the any performance increase when going parallel will
- * depend on the size of the input (lines) and the cost per-element.
- */
- WCStatistics wc = reader.lines().parallel()
- .collect(WCStatistics::new,
- WCStatistics::accept,
- WCStatistics::combine);
- System.out.println(wc);
- }
-
- private static void usage() {
- System.out.println("Usage: " + WC.class.getSimpleName() + " FILE");
- System.out.println("Print newline, word,"
- + " character counts and max line length for FILE.");
- }
-
- private static class WCStatistics implements Consumer
- * Animal
- * / \
- * Horse Bird
- * \ /
- * Pegasus
- *
- *
- * Both {@link Horse} and {@link Bird} interfaces implements the go
- * method. The {@link Pegasus} class have to overrides the
- * go method.
- *
- * The new syntax of super-call is used here:
- *
- * <interface_name>.super.<method>(...);
- * For example: Horse.super.go();
- *
So, Pegasus moves like a horse.
- */
-public class DiamondInheritance {
-
- /**
- * Base interface to illustrate the diamond inheritance.
- *
- * @see DiamondInheritance
- */
- public interface Animal {
-
- /**
- * Return string representation of the "go" action for concrete animal
- *
- * @return string representation of the "go" action for concrete animal
- */
- String go();
- }
-
- /**
- * Interface to illustrate the diamond inheritance.
- *
- * @see DiamondInheritance
- */
- public interface Horse extends Animal {
-
- /**
- * Return string representation of the "go" action for horse
- *
- * @return string representation of the "go" action for horse
- */
- @Override
- default String go() {
- return this.getClass().getSimpleName() + " walks on four legs";
- }
- }
-
- /**
- * Interface to illustrate the diamond inheritance.
- *
- * @see DiamondInheritance
- */
- public interface Bird extends Animal {
-
- /**
- * Return string representation of the "go" action for bird
- *
- * @return string representation of the "go" action for bird
- */
- @Override
- default String go() {
- return this.getClass().getSimpleName() + " walks on two legs";
- }
-
- /**
- * Return string representation of the "fly" action for bird
- *
- * @return string representation of the "fly" action for bird
- */
- default String fly() {
- return "I can fly";
- }
- }
-
- /**
- * Class to illustrate the diamond inheritance. Pegasus must mix horse and
- * bird behavior.
- *
- * @see DiamondInheritance
- */
- public static class Pegasus implements Horse, Bird {
-
- /**
- * Return string representation of the "go" action for the fictitious
- * creature Pegasus
- *
- * @return string representation of the "go" action for the fictitious
- * creature Pegasus
- */
- @Override
- public String go() {
- return Horse.super.go();
- }
- }
-
- /**
- * Illustrate the behavior of the {@link Pegasus} class
- *
- * @param args command line arguments
- */
- public static void main(final String[] args) {
- System.out.println(new Pegasus().go());
- }
-}
diff --git a/jdk/src/sample/share/lambda/DefaultMethods/Inheritance.java b/jdk/src/sample/share/lambda/DefaultMethods/Inheritance.java
deleted file mode 100644
index 961de2c24d5..00000000000
--- a/jdk/src/sample/share/lambda/DefaultMethods/Inheritance.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/**
- * The sample illustrates rules to resolve conflicts between inheritance
- * candidates with default methods. There are two simple rules:
- *
- *
- */
-public class Inheritance {
-
- /**
- * The behavior of an creature that can swim
- */
- public interface Swimable {
-
- /**
- * Return string representation of the swim action for a creature that
- * can swim
- *
- * @return string representation of the swim action for a creature
- * that can swim
- */
- default String swim() {
- return "I can swim.";
- }
- }
-
- /**
- * The abstract class that overrides {@link #swim} method
- */
- public abstract static class Fish implements Swimable {
-
- /**
- * Return string representation of the swim action for a fish
- *
- * @return string representation of the swim action for a fish
- */
- @Override
- public String swim() {
- return this.getClass().getSimpleName() + " swims under water";
- }
- }
-
- /**
- * This class is used for the illustration rule of 1. See the source code
- * of the {@link #main} method.
- *
- * System.out.println(new Tuna().swim()); //"Tuna swims under water" output is suspected here
- *
- */
- public static class Tuna extends Fish implements Swimable {
- }
-
- /**
- * The behavior of an creature that can dive: the interface that overrides
- * {@link #swim} method (subtype of {@link Swimable})
- */
- public interface Diveable extends Swimable {
-
- /**
- * Return string representation of the swim action for a creature that
- * can dive
- *
- * @return string representation of the swim action for a creature
- * that can dive
- */
- @Override
- default String swim() {
- return "I can swim on the surface of the water.";
- }
-
- /**
- * Return string representation of the dive action for a creature that
- * can dive
- *
- * @return string representation of the dive action for a creature
- * that can dive
- */
- default String dive() {
- return "I can dive.";
- }
- }
-
- /**
- * This class is used for the illustration of rule 2. See the source code
- * of the {@link #main} method
- *
- * //"I can swim on the surface of the water." output is suspected here
- * System.out.println(new Duck().swim());
- *
- */
- public static class Duck implements Swimable, Diveable {
- }
-
- /**
- * Illustrate behavior of the classes: {@link Tuna} and {@link Duck}
- *
- * @param args command line arguments
- */
- public static void main(final String[] args) {
- // Illustrates rule 1. The Fish.swim() implementation wins
- //"Tuna swims under water" is output
- System.out.println(new Tuna().swim());
-
- // Illustrates rule 2. The Diveable.swim() implementation wins
- //"I can swim on the surface of the water." is output
- System.out.println(new Duck().swim());
- }
-}
diff --git a/jdk/src/sample/share/lambda/DefaultMethods/MixIn.java b/jdk/src/sample/share/lambda/DefaultMethods/MixIn.java
deleted file mode 100644
index d9ed81dee27..00000000000
--- a/jdk/src/sample/share/lambda/DefaultMethods/MixIn.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import java.io.IOException;
-import java.lang.reflect.Field;
-
-/**
- * The example illustrates how to use the default method for mixin.
- * @see BuildType
- * @see Debuggable
- */
-public class MixIn {
-
- /**
- * Implement this interface for a class that must be in debug print
- */
- public interface Debuggable {
-
- /**
- * Print the class name and all fields to a string. Uses reflection to
- * obtain and access fields of this object.
- *
- * @return the string formatted like the following:
- * State of the: <Class Name>
- * <member name> : <value>
- * ...
- *
- */
- default String toDebugString() {
- StringBuilder sb = new StringBuilder();
- sb.append("State of the: ").append(
- this.getClass().getSimpleName()).append("\n");
- for (Class cls = this.getClass();
- cls != null;
- cls = cls.getSuperclass()) {
- for (Field f : cls.getDeclaredFields()) {
- try {
- f.setAccessible(true);
- sb.append(f.getName()).append(" : ").
- append(f.get(this)).append("\n");
- } catch (IllegalAccessException e) {
- }
- }
- }
- return sb.toString();
- }
- }
-
- /**
- * Sample exception class to demonstrate mixin. This enum inherits the
- * behavior of the {@link Debuggable}
- */
- public static enum BuildType implements Debuggable {
-
- BUILD(0, "-build"),
- PLAN(0, "-plan"),
- EXCLUDE(1, "-exclude"),
- TOTAL(2, "-total");
-
- private final int compareOrder;
- private final String pathSuffix;
-
- private BuildType(int compareOrder, String pathSuffix) {
- this.compareOrder = compareOrder;
- this.pathSuffix = pathSuffix;
- }
-
- public int getCompareOrder() {
- return compareOrder;
- }
-
- public String getPathSuffix() {
- return pathSuffix;
- }
- }
-
- /**
- * Illustrate the behavior of the MixClass
- *
- * @param args command-line arguments
- * @throws java.io.IOException internal demo error
- */
- public static void main(final String[] args) throws IOException {
- System.out.println(BuildType.BUILD.toDebugString());
- }
-}
diff --git a/jdk/src/sample/share/lambda/DefaultMethods/Reflection.java b/jdk/src/sample/share/lambda/DefaultMethods/Reflection.java
deleted file mode 100644
index 78424a240e8..00000000000
--- a/jdk/src/sample/share/lambda/DefaultMethods/Reflection.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.stream.Stream;
-
-/**
- * The code sample illustrates changes in the reflection API linked
- * default methods. Since Java SE 8, a new method is added into the class
- * java.lang.reflect.Method, with which you can reflectively
- * determine whether or not a default method provided by an interface
- * (Method.isDefault()).
- */
-public class Reflection {
-
- /**
- * Base interface to illustrate the new reflection API.
- *
- * @see Dog
- */
- public interface Animal {
-
- /**
- * Return string representation of the eat action for Animal
- *
- * @return string representation of the eat action for Animal
- */
- default String eat() {
- return this.getClass().getSimpleName()
- + " eats like an ordinary animal";
- }
-
- /**
- * Return string representation of the sleep action for Animal
- *
- * @return string representation of the sleep action for Animal
- */
- default String sleep() {
- return this.getClass().getSimpleName()
- + " sleeps like an ordinary animal";
- }
-
- /**
- * Return string representation of the go action for Animal
- *
- * @return string representation of the go action for Animal
- */
- String go();
- }
-
- /**
- * Dog class to illustrate the new reflection API. You can see that:
- *
- *
- */
- public static class Dog implements Animal {
-
- /**
- * Return string representation of the go action for Dog
- *
- * @return string representation of the go action for Dog
- */
- @Override
- public String go() {
- return "Dog walks on four legs";
- }
-
- /**
- * Return string representation of the sleep action for Dog
- *
- * @return string representation of the sleep action for Dog
- */
- @Override
- public String sleep() {
- return "Dog sleeps";
- }
- }
-
- /**
- * Illustrate the usage of the method java.lang.reflect.Method.isDefault()
- *
- * @param args command-line arguments
- * @throws NoSuchMethodException internal demo error
- */
- public static void main(final String[] args) throws NoSuchMethodException {
- Dog dog = new Dog();
- Stream.of(Dog.class.getMethod("eat"), Dog.class.getMethod("go"), Dog.class.getMethod("sleep"))
- .forEach((m) -> {
- System.out.println("Method name: " + m.getName());
- System.out.println(" isDefault: " + m.isDefault());
- System.out.print(" invoke: ");
- try {
- m.invoke(dog);
- } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
- }
- System.out.println();
- });
- }
-}
diff --git a/jdk/src/sample/share/lambda/DefaultMethods/SimplestUsage.java b/jdk/src/sample/share/lambda/DefaultMethods/SimplestUsage.java
deleted file mode 100644
index a971858f589..00000000000
--- a/jdk/src/sample/share/lambda/DefaultMethods/SimplestUsage.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/**
- * The sample illustrates the simplest use case of the default methods.
- */
-public class SimplestUsage {
-
- /**
- * The Animal interface provides the default implementation
- * of the {@link #eat} method.
- */
- public interface Animal {
-
- /**
- * Return string representation of the eat action for Animal
- *
- * @return string representation of the eat action for Animal
- */
- default String eat() {
- return this.getClass().getSimpleName()
- + " eats like an ordinary animal";
- }
- }
-
- /**
- * The Dog class doesn't have its own implementation of the {@link #eat}
- * method and uses the default implementation.
- */
- public static class Dog implements Animal {
- }
-
- /**
- * The Mosquito class implements {@link #eat} method, its own implementation
- * overrides the default implementation.
- *
- */
- public static class Mosquito implements Animal {
-
- /**
- * Return string representation of the eat action for Mosquito
- *
- * @return string representation of the eat action for Mosquito
- */
- @Override
- public String eat() {
- return "Mosquito consumes blood";
- }
- }
-
- /**
- * Illustrate behavior of the classes: {@link Dog} and {@link Mosquito}
- *
- * @param args command-line arguments
- */
- public static void main(String[] args) {
- // "Dog eats like an ordinary animal" is output
- System.out.println(new Dog().eat());
-
- // "Mosquito consumes blood" is output
- System.out.println(new Mosquito().eat());
- }
-}
diff --git a/jdk/src/sample/share/nbproject/project.xml b/jdk/src/sample/share/nbproject/project.xml
deleted file mode 100644
index 8417326b624..00000000000
--- a/jdk/src/sample/share/nbproject/project.xml
+++ /dev/null
@@ -1,50 +0,0 @@
-
-
-
-
-
- * who operator [permissions]
- *
- * where who is one or more of the characters {@code 'u'}, {@code 'g'},
- * {@code 'o'}, or {@code 'a'} meaning the owner (user), group, others, or
- * all (owner, group, and others) respectively.
- *
- *
- *
- *
- * @param exprs
- * List of one or more symbolic mode expressions
- *
- * @return A {@code Changer} that may be used to changer a set of
- * file permissions
- *
- * @throws IllegalArgumentException
- * If the value of the {@code exprs} parameter is invalid
- */
- public static Changer compile(String exprs) {
- // minimum is who and operator (u= for example)
- if (exprs.length() < 2)
- throw new IllegalArgumentException("Invalid mode");
-
- // permissions that the changer will add or remove
- final Set
- *
- * {@code u=rw}
- * Sets the owner permissions to be read and write.
- *
- *
- * {@code ug+w}
- * Sets the owner write and group write permissions.
- *
- *
- * {@code u+w,o-rwx}
- * Sets the owner write, and removes the others read, others write
- * and others execute permissions.
- *
- *
- * {@code o=}
- * Sets the others permission to none (others read, others write and
- * others execute permissions are removed if set)
- *
- * Application Data
- * src requestBB
- * | ^
- * | | |
- * v | |
- * +----+-----|-----+----+
- * | | |
- * | SSL|Engine |
- * wrap() | | | unwrap()
- * | OUTBOUND | INBOUND |
- * | | |
- * +----+-----|-----+----+
- * | | ^
- * | | |
- * v |
- * outNetBB inNetBB
- * Net data
- *
- *
- * These buffers handle all of the intermediary data for the SSL
- * connection. To make things easy, we'll require outNetBB be
- * completely flushed before trying to wrap any more data, but we
- * could certainly remove that restriction by using larger buffers.
- * ");
- var itr = names.iterator();
- while (itr.hasNext()) {
- var name = itr.next();
- helpDoc.append("
");
-
- var helpEditor = new guiPkgs.JEditorPane();
- helpEditor.setContentType("text/html");
- helpEditor.setEditable(false);
- helpEditor.setText(helpDoc.toString());
-
- var scroller = new guiPkgs.JScrollPane();
- var port = scroller.getViewport();
- port.add(helpEditor);
-
- var helpFrame = new guiPkgs.JFrame("Help - Global Functions");
- helpFrame.getContentPane().add("Center", scroller);
- helpFrame.setDefaultCloseOperation(guiPkgs.WindowConstants.DISPOSE_ON_CLOSE);
- helpFrame.pack();
- helpFrame.setSize(500, 600);
- helpFrame.setVisible(true);
- }
-
- // show a simple about message for scriptpad
- function actionAbout() {
- alert("Scriptpad\nVersion 1.1", "Scriptpad");
- }
-
- /*
- * This data is used to construct menu bar.
- * This way adding a menu is easier. Just add
- * top level menu or add an item to an existing
- * menu. "action" should be a function that is
- * called back on clicking the correponding menu.
- */
- var menuData = [
- {
- menu: "File",
- items: [
- { name: "New", action: actionNew , accel: guiPkgs.KeyEvent.VK_N },
- { name: "Open...", action: actionOpen, accel: guiPkgs.KeyEvent.VK_O },
- { name: "Open URL...", action: actionOpenURL, accel: guiPkgs.KeyEvent.VK_U },
- { name: "Save", action: actionSave, accel: guiPkgs.KeyEvent.VK_S },
- { name: "Save As...", action: actionSaveAs },
- { name: "-" },
- { name: "Exit", action: actionExit, accel: guiPkgs.KeyEvent.VK_Q }
- ]
- },
-
- {
- menu: "Edit",
- items: [
- { name: "Cut", action: actionCut, accel: guiPkgs.KeyEvent.VK_X },
- { name: "Copy", action: actionCopy, accel: guiPkgs.KeyEvent.VK_C },
- { name: "Paste", action: actionPaste, accel: guiPkgs.KeyEvent.VK_V },
- { name: "-" },
- { name: "Select All", action: actionSelectAll, accel: guiPkgs.KeyEvent.VK_A }
- ]
- },
-
- {
- menu: "Tools",
- items: [
- { name: "Run", action: actionRun, accel: guiPkgs.KeyEvent.VK_R }
- ]
- },
-
- {
- menu: "Examples",
- items: [
- { name: actionHello.title, action: actionHello },
- { name: actionEval.title, action: actionEval },
- { name: actionJavaStatic.title, action: actionJavaStatic },
- { name: actionJavaAccess.title, action: actionJavaAccess },
- { name: actionJavaBean.title, action: actionJavaBean },
- { name: actionJavaInterface.title, action: actionJavaInterface },
- { name: actionJavaImport.title, action: actionJavaImport }
- ]
- },
-
- {
- menu: "Help",
- items: [
- { name: "Global Functions", action: actionHelpGlobals },
- { name: "-" },
- { name: "About Scriptpad", action: actionAbout }
- ]
- }
- ];
-
- function setMenuAccelerator(mi, accel) {
- var keyStroke = guiPkgs.KeyStroke.getKeyStroke(accel,
- guiPkgs.Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false);
- mi.setAccelerator(keyStroke);
- }
-
- // create a menubar using the above menu data
- function createMenubar() {
- var mb = new guiPkgs.JMenuBar();
- for (var m in menuData) {
- var items = menuData[m].items;
- var menu = new guiPkgs.JMenu(menuData[m].menu);
-
- for (var i in items) {
- if (items[i].name.equals("-")) {
- menu.addSeparator();
- } else {
- var mi = new guiPkgs.JMenuItem(items[i].name);
- var action = items[i].action;
- mi.addActionListener(action);
- var accel = items[i].accel;
- if (accel) {
- setMenuAccelerator(mi, accel);
- }
- menu.add(mi);
- }
- }
-
- mb.add(menu);
- }
-
- return mb;
- }
-
- // function to add a new menu item under "Tools" menu
- function addTool(menuItem, action, accel) {
- if (typeof(action) != "function") {
- return;
- }
-
- var toolsIndex = -1;
- // find the index of the "Tools" menu
- for (var i in menuData) {
- if (menuData[i].menu.equals("Tools")) {
- toolsIndex = i;
- break;
- }
- }
- if (toolsIndex == -1) {
- return;
- }
- var toolsMenu = frame.getJMenuBar().getMenu(toolsIndex);
- var mi = new guiPkgs.JMenuItem(menuItem);
- mi.addActionListener(action);
- if (accel) {
- setMenuAccelerator(mi, accel);
- }
- toolsMenu.add(mi);
- }
-
- // create Scriptpad frame
- function createFrame() {
- frame = new guiPkgs.JFrame();
- frame.setTitle(defaultTitle);
- frame.setBackground(guiPkgs.Color.lightGray);
- frame.getContentPane().setLayout(new guiPkgs.BorderLayout());
-
- // create notepad panel
- var notepad = new guiPkgs.JPanel();
- notepad.setBorder(guiPkgs.BorderFactory.createEtchedBorder());
- notepad.setLayout(new guiPkgs.BorderLayout());
-
- // create editor
- editor = createEditor();
- var scroller = new guiPkgs.JScrollPane();
- var port = scroller.getViewport();
- port.add(editor);
-
- // add editor to notepad panel
- var panel = new guiPkgs.JPanel();
- panel.setLayout(new guiPkgs.BorderLayout());
- panel.add("Center", scroller);
- notepad.add("Center", panel);
-
- // add notepad panel to frame
- frame.getContentPane().add("Center", notepad);
-
- // set menu bar to frame and show the frame
- frame.setJMenuBar(createMenubar());
- frame.setDefaultCloseOperation(guiPkgs.JFrame.EXIT_ON_CLOSE);
- frame.pack();
- frame.setSize(500, 600);
- }
-
- // show Scriptpad frame
- function showFrame() {
- // set global variable by the name "window"
- globalThis.window = frame;
-
- // open new document
- actionNew();
-
- frame.setVisible(true);
- }
-
- // create and show Scriptpad frame
- createFrame();
- showFrame();
-
- /*
- * Application object has two fields "frame", "editor"
- * which are current JFrame and editor and a method
- * called "addTool" to add new menu item to "Tools" menu.
- */
- return {
- frame: frame,
- editor: editor,
- addTool: addTool
- };
-};
-
-/*
- * Call the main and store Application object
- * in a global variable named "application".
- */
-var application = main();
-
-if (this.load == undefined) {
- function load(file) {
- var ioPkgs = new JavaImporter(java.io);
- with (ioPkgs) {
- var stream = new FileInputStream(file);
- var bstream = new BufferedInputStream(stream);
- var reader = new BufferedReader(new InputStreamReader(bstream));
- var oldFilename = engine.get(engine.FILENAME);
- engine.put(engine.FILENAME, file);
- try {
- engine.eval(reader, context);
- } finally {
- engine.put(engine.FILENAME, oldFilename);
- }
- stream.close();
- }
- }
- load.docString = "loads the given script file";
-}
-
-/*
- * Load user specific init file under home dir, if found.
- */
-function loadUserInit() {
- var home = java.lang.System.getProperty("user.home");
- var f = new java.io.File(home, "scriptpad.js");
- if (f.exists()) {
- engine.eval(new java.io.FileReader(f));
- }
-}
-
-loadUserInit();
diff --git a/jdk/src/sample/share/scripting/scriptpad/src/scripts/README.txt b/jdk/src/sample/share/scripting/scriptpad/src/scripts/README.txt
deleted file mode 100644
index 72e162d6fff..00000000000
--- a/jdk/src/sample/share/scripting/scriptpad/src/scripts/README.txt
+++ /dev/null
@@ -1,52 +0,0 @@
-Sample scripts:
-
-(1) browse.js
-
- -- Open and run this script in scriptpad. You will see
- Tools->Browse menu. Using this you can start your
- desktop default browser with the given URL.
-
-(2) insertfile.js
-
- -- Open and run this script in scriptpad. You will see
- "Tools->Insert File..." menu. Using this you can start
- insert content of a selected file into currently
- edited document
-
-(3) linewrap.js
-
- -- Open and run this script in scriptpad. You will see
- "Tools->Line Wrap" menu. Using this you can toggle
- the line wrapping mode of the editor
-
-(4) mail.js
-
- -- Open and run this script in scriptpad. You will see
- Tools->Mail menu. Using this you can start your
- desktop default mail client with the given "To" mail id.
-
-(5) memmonitor.js
-
- -- This is a simple Monitoring & Management script. To use this,
- you need an application to monitor. You can use memory.bat
- or memory.sh in the current directory to start an application
- that will be monitored. After that please follow these steps:
-
- 1. Start the target application using memory.sh or memory.bat
- 2. Start scriptpad
- 3. Use "Tools->JMX Connect" menu and specify "localhost:1090"
- to connect
- 4. Open "memmonitor.js" and run it (using "Tools->Run")
- in scriptpad
- 5. A new "Tools-Memory Monitor" menu appears. Use this menu
- and specify 4 and 500 as threshold and interval values.
- 6. In the target application shell (where memory.bat/.sh was
- started), enter an integer value and press "enter".
- 7. You'll see an alert box from scriptpad -- alerting you for
- memory threshold exceeded!
-
-(6) textcolor.js
-
- -- Open and run this script in scriptpad. You will see
- "Tools->Selected Text Color..." menu. Using this you
- change the color of "selected text" in the editor.
diff --git a/jdk/src/sample/share/scripting/scriptpad/src/scripts/browse.js b/jdk/src/sample/share/scripting/scriptpad/src/scripts/browse.js
deleted file mode 100644
index fbe50e1a414..00000000000
--- a/jdk/src/sample/share/scripting/scriptpad/src/scripts/browse.js
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-/*
- * This function uses new Swing Desktop API in JDK 6.
- * To use this with scriptpad, open this in scriptpad
- * and use "Tools->Run Script" menu.
- */
-function browse() {
- var desktop = null;
- // Before more Desktop API is used, first check
- // whether the API is supported by this particular
- // virtual machine (VM) on this particular host.
- if (java.awt.Desktop.isDesktopSupported()) {
- desktop = java.awt.Desktop.getDesktop();
- } else {
- alert("no desktop support");
- return;
- }
-
- if (desktop.isSupported(java.awt.Desktop.Action.BROWSE)) {
- var url = prompt("Address:");
- if (url != null) {
- desktop.browse(new java.net.URI(url));
- }
- } else {
- alert("no browser support");
- }
-}
-
-if (this.application != undefined) {
- // add "Browse" menu item under "Tools" menu
- this.application.addTool("Browse", browse);
-}
diff --git a/jdk/src/sample/share/scripting/scriptpad/src/scripts/insertfile.js b/jdk/src/sample/share/scripting/scriptpad/src/scripts/insertfile.js
deleted file mode 100644
index 07a7ac28d19..00000000000
--- a/jdk/src/sample/share/scripting/scriptpad/src/scripts/insertfile.js
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-/*
- * This script adds "Insert File" mode menu item to "Tools" menu.
- * When selected, this menu shows a file dialog box and inserts
- * contents of the selected file into current document (at the
- * current caret position).
- */
-if (this.application) {
- application.addTool("Insert File...",
- function() {
- var file = fileDialog();
-
- if (file) {
- var reader = new java.io.FileReader(file);
- var arr = java.lang.reflect.Array.newInstance(
- java.lang.Character.TYPE, 8*1024); // 8K at a time
- var buf = new java.lang.StringBuffer();
- var numChars;
-
- while ((numChars = reader.read(arr, 0, arr.length)) > 0) {
- buf.append(arr, 0, numChars);
- }
-
- var pos = application.editor.caretPosition;
- var doc = application.editor.document;
-
- doc.insertString(pos, buf.toString(), null);
- }
- });
-}
diff --git a/jdk/src/sample/share/scripting/scriptpad/src/scripts/linewrap.js b/jdk/src/sample/share/scripting/scriptpad/src/scripts/linewrap.js
deleted file mode 100644
index 989473a6cf1..00000000000
--- a/jdk/src/sample/share/scripting/scriptpad/src/scripts/linewrap.js
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-/*
- * This script adds "Line Wrap" mode menu item to "Tools" menu.
- * When selected, this menu toggles the current word wrap mode
- * of the editor.
- */
-
-function toggleLineWrap() {
- var wrap = application.editor.lineWrap;
- application.editor.lineWrap = !wrap;
-}
-
-application.addTool("Line Wrap", toggleLineWrap);
diff --git a/jdk/src/sample/share/scripting/scriptpad/src/scripts/mail.js b/jdk/src/sample/share/scripting/scriptpad/src/scripts/mail.js
deleted file mode 100644
index cabe5c47541..00000000000
--- a/jdk/src/sample/share/scripting/scriptpad/src/scripts/mail.js
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-/*
- * This function uses new Swing Desktop API in JDK 6.
- * To use this with scriptpad, open this in scriptpad
- * and use "Tools->Run Script" menu.
- */
-function mail() {
- var desktop = null;
- // Before more Desktop API is used, first check
- // whether the API is supported by this particular
- // virtual machine (VM) on this particular host.
- if (java.awt.Desktop.isDesktopSupported()) {
- desktop = java.awt.Desktop.getDesktop();
- } else {
- alert("no desktop support");
- return;
- }
-
- if (desktop.isSupported(java.awt.Desktop.Action.MAIL)) {
- var mailTo = prompt("Mail To:");
- if (mailTo != null) {
- desktop.mail(new java.net.URI("mailto", mailTo, null));
- }
- }
-}
-
-if (this.application != undefined) {
- // add "Mail" menu item under "Tools" menu
- this.application.addTool("Mail", mail);
-}
diff --git a/jdk/src/sample/share/scripting/scriptpad/src/scripts/memmonitor.js b/jdk/src/sample/share/scripting/scriptpad/src/scripts/memmonitor.js
deleted file mode 100644
index 0744e303b78..00000000000
--- a/jdk/src/sample/share/scripting/scriptpad/src/scripts/memmonitor.js
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-// this checker function runs asynchronously
-function memoryChecker(memoryBean, threshold, interval) {
- while (true) {
- var memUsage = memoryBean.HeapMemoryUsage;
- var usage = memUsage.get("used") / (1024 * 1024);
-
- println("usage: " + usage);
-
- if (usage > threshold) {
- alert("Hey! heap usage threshold exceeded!");
- // after first alert just return.
- return;
- }
-
- java.lang.Thread.sleep(interval);
- }
-}
-
-// add "Tools->Memory Monitor" menu item
-if (this.application != undefined) {
- this.application.addTool("Memory Monitor",
- function () {
- // show threshold box with default of 50 MB
- var threshold = prompt("Threshold (mb)", 50);
-
- // show interval box with default of 1000 millisec.
- var interval = prompt("Sample Interval (ms):", 1000);
- var memoryBean = mbean("java.lang:type=Memory");
-
- // ".future" makes the function to be called
- // asynchronously in a separate thread.
- memoryChecker.future(memoryBean, threshold, interval);
- });
-}
diff --git a/jdk/src/sample/share/scripting/scriptpad/src/scripts/memory.bat b/jdk/src/sample/share/scripting/scriptpad/src/scripts/memory.bat
deleted file mode 100644
index 9478c0966c1..00000000000
--- a/jdk/src/sample/share/scripting/scriptpad/src/scripts/memory.bat
+++ /dev/null
@@ -1,35 +0,0 @@
-@echo off
-REM
-REM Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
-REM
-REM Redistribution and use in source and binary forms, with or without
-REM modification, are permitted provided that the following conditions
-REM are met:
-REM
-REM - Redistributions of source code must retain the above copyright
-REM notice, this list of conditions and the following disclaimer.
-REM
-REM - Redistributions in binary form must reproduce the above copyright
-REM notice, this list of conditions and the following disclaimer in the
-REM documentation and/or other materials provided with the distribution.
-REM
-REM - Neither the name of Oracle nor the names of its
-REM contributors may be used to endorse or promote products derived
-REM from this software without specific prior written permission.
-REM
-REM THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
-REM IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-REM THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-REM PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
-REM CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-REM EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-REM PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-REM PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-REM LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-REM NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-REM SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-REM
-
-
-jrunscript -J-Dcom.sun.management.jmxremote.port=1090 -J-Dcom.sun.management.jmxremote.ssl=false -J-Dcom.sun.management.jmxremote.authenticate=false memory.js
-
diff --git a/jdk/src/sample/share/scripting/scriptpad/src/scripts/memory.js b/jdk/src/sample/share/scripting/scriptpad/src/scripts/memory.js
deleted file mode 100644
index b8252fbfbcc..00000000000
--- a/jdk/src/sample/share/scripting/scriptpad/src/scripts/memory.js
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-/*
- * This script serves as a simple "monitored application".
- * Start this script using memory.bat or memory.sh in the
- * current directory.
- */
-
-java.lang.System.out.print("Enter a number and press enter:");
-var input = java.lang.System["in"].read();
-
-// allocate an integer array of "big enough" size!
-var a = java.lang.reflect.Array.newInstance(
- java.lang.Integer.TYPE, input * 1024 * 1024);
-
-// sleep some time...
-java.lang.Thread.sleep(10*60*1000);
diff --git a/jdk/src/sample/share/scripting/scriptpad/src/scripts/memory.sh b/jdk/src/sample/share/scripting/scriptpad/src/scripts/memory.sh
deleted file mode 100644
index 8da155bbdba..00000000000
--- a/jdk/src/sample/share/scripting/scriptpad/src/scripts/memory.sh
+++ /dev/null
@@ -1,32 +0,0 @@
-#
-# Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# - Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-#
-# - Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-#
-# - Neither the name of Oracle nor the names of its
-# contributors may be used to endorse or promote products derived
-# from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
-# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
-# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-jrunscript -J-Dcom.sun.management.jmxremote.port=1090 -J-Dcom.sun.management.jmxremote.ssl=false -J-Dcom.sun.management.jmxremote.authenticate=false memory.js
diff --git a/jdk/src/sample/share/scripting/scriptpad/src/scripts/textcolor.js b/jdk/src/sample/share/scripting/scriptpad/src/scripts/textcolor.js
deleted file mode 100644
index b9d86cc37f0..00000000000
--- a/jdk/src/sample/share/scripting/scriptpad/src/scripts/textcolor.js
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-/*
- * This script adds "Selected Text Color" menu item to "Tools" menu.
- * When selected, this menu changes the "selected text" color.
- */
-if (this.application) {
- application.addTool("Selected Text Color...",
- function() {
- var color = application.editor.selectedTextColor;
- color = colorDialog("Selected Text Color", color);
- application.editor.selectedTextColor = color;
- });
-}
diff --git a/jdk/src/sample/share/try-with-resources/index.html b/jdk/src/sample/share/try-with-resources/index.html
deleted file mode 100644
index 97aecf317d0..00000000000
--- a/jdk/src/sample/share/try-with-resources/index.html
+++ /dev/null
@@ -1,36 +0,0 @@
-
-
-
-
- ");
- }
- helpDoc.append("");
- helpDoc.append(name);
- helpDoc.append(" ");
- helpDoc.append(globalThis[name].docString);
- helpDoc.append(" Try-with-Resources Feature Demo
-
-
-
-
-
diff --git a/jdk/src/sample/share/try-with-resources/src/CustomAutoCloseableSample.java b/jdk/src/sample/share/try-with-resources/src/CustomAutoCloseableSample.java
deleted file mode 100644
index 9bbe09aa1ed..00000000000
--- a/jdk/src/sample/share/try-with-resources/src/CustomAutoCloseableSample.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation, and proper error handling, might not be present in
- * this sample code.
- */
-
-import java.io.BufferedOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.PrintStream;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-
-/**
- * This sample demonstrates the ability to create custom resource that
- * implements the {@code AutoCloseable} interface. This resource can be used in
- * the try-with-resources construct.
- */
-public class CustomAutoCloseableSample {
-
- /**
- * The main method for the CustomAutoCloseableSample program.
- *
- * @param args is not used.
- */
- public static void main(String[] args) {
- /*
- * TeeStream will be closed automatically after the try block.
- */
- try (TeeStream teeStream = new TeeStream(System.out, Paths.get("out.txt"));
- PrintStream out = new PrintStream(teeStream)) {
- out.print("Hello, world");
- } catch (Exception e) {
- e.printStackTrace();
- System.exit(1);
- }
- }
-
- /**
- * Passes the output through to the specified output stream while copying it into a file.
- * The TeeStream functionality is similar to the Unix tee utility.
- * TeeStream implements AutoCloseable interface. See OutputStream for details.
- */
- public static class TeeStream extends OutputStream {
-
- private final OutputStream fileStream;
- private final OutputStream outputStream;
-
- /**
- * Creates a TeeStream.
- *
- * @param outputStream an output stream.
- * @param outputFile an path to file.
- * @throws IOException If an I/O error occurs.
- */
- public TeeStream(OutputStream outputStream, Path outputFile) throws IOException {
- this.fileStream = new BufferedOutputStream(Files.newOutputStream(outputFile));
- this.outputStream = outputStream;
- }
-
- /**
- * Writes the specified byte to the specified output stream
- * and copies it to the file.
- *
- * @param b the byte to be written.
- * @throws IOException If an I/O error occurs.
- */
- @Override
- public void write(int b) throws IOException {
- fileStream.write(b);
- outputStream.write(b);
- }
-
- /**
- * Flushes this output stream and forces any buffered output bytes
- * to be written out.
- * The Custom AutoCloseable.
-
- Unzip
-
- ZipCat
-
- flush method of TeeStream flushes
- * the specified output stream and the file output stream.
- *
- * @throws IOException if an I/O error occurs.
- */
- @Override
- public void flush() throws IOException {
- outputStream.flush();
- fileStream.flush();
- }
-
- /**
- * Closes underlying streams and resources.
- * The external output stream won't be closed.
- * This method is the member of AutoCloseable interface and
- * it will be invoked automatically after the try-with-resources block.
- *
- * @throws IOException If an I/O error occurs.
- */
- @Override
- public void close() throws IOException {
- try (OutputStream file = fileStream) {
- flush();
- }
- }
- }
-}
diff --git a/jdk/src/sample/share/try-with-resources/src/Unzip.java b/jdk/src/sample/share/try-with-resources/src/Unzip.java
deleted file mode 100644
index d75eba52c78..00000000000
--- a/jdk/src/sample/share/try-with-resources/src/Unzip.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation, and proper error handling, might not be present in
- * this sample code.
- */
-
-import java.io.IOException;
-import java.io.UncheckedIOException;
-import java.nio.file.*;
-
-import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
-
-/**
- * Extract (unzip) a file to the current directory.
- */
-public class Unzip {
-
- /**
- * The main method for the Unzip program. Run the program with an empty
- * argument list to see possible arguments.
- *
- * @param args the argument list for {@code Unzip}.
- */
- public static void main(String[] args) {
- if (args.length != 1) {
- System.out.println("Usage: Unzip zipfile");
- }
- final Path destDir = Paths.get(".");
- /*
- * Create AutoCloseable FileSystem. It will be closed automatically
- * after the try block.
- */
- try (FileSystem zipFileSystem = FileSystems.newFileSystem(Paths.get(args[0]), null)) {
-
- Path top = zipFileSystem.getPath("/");
- Files.walk(top).skip(1).forEach(file -> {
- Path target = destDir.resolve(top.relativize(file).toString());
- System.out.println("Extracting " + target);
- try {
- Files.copy(file, target, REPLACE_EXISTING);
- } catch (IOException e) {
- throw new UncheckedIOException(e);
- }
- });
- } catch (UncheckedIOException | IOException e) {
- e.printStackTrace();
- System.exit(1);
- }
- }
-}
diff --git a/jdk/src/sample/share/try-with-resources/src/ZipCat.java b/jdk/src/sample/share/try-with-resources/src/ZipCat.java
deleted file mode 100644
index 4bbf513a538..00000000000
--- a/jdk/src/sample/share/try-with-resources/src/ZipCat.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation, and proper error handling, might not be present in
- * this sample code.
- */
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.file.FileSystem;
-import java.nio.file.FileSystems;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-
-/**
- * Prints data of the specified file to standard output from a zip archive.
- */
-public class ZipCat {
-
- /**
- * The main method for the ZipCat program. Run the program with an empty
- * argument list to see possible arguments.
- *
- * @param args the argument list for ZipCat
- */
- public static void main(String[] args) {
- if (args.length != 2) {
- System.out.println("Usage: ZipCat zipfile fileToPrint");
- }
- /*
- * Creates AutoCloseable FileSystem and BufferedReader.
- * They will be closed automatically after the try block.
- * If reader initialization fails, then zipFileSystem will be closed
- * automatically.
- */
- try (FileSystem zipFileSystem
- = FileSystems.newFileSystem(Paths.get(args[0]),null);
- InputStream input
- = Files.newInputStream(zipFileSystem.getPath(args[1]))) {
- byte[] buffer = new byte[1024];
- int len;
- while ((len = input.read(buffer)) != -1) {
- System.out.write(buffer, 0, len);
- }
-
- } catch (IOException e) {
- e.printStackTrace();
- System.exit(1);
- }
- }
-}
diff --git a/jdk/src/sample/share/vm/clr-jvm/Makefile b/jdk/src/sample/share/vm/clr-jvm/Makefile
deleted file mode 100644
index 0a5c3316668..00000000000
--- a/jdk/src/sample/share/vm/clr-jvm/Makefile
+++ /dev/null
@@ -1,44 +0,0 @@
-#
-# Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# - Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-#
-# - Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-#
-# - Neither the name of Oracle nor the names of its
-# contributors may be used to endorse or promote products derived
-# from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
-# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
-# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-all: jinvoker.dll invoked.class invoker.exe
-
-jinvoker.dll: jinvoker.obj Makefile
- cl /LD /o jinvoker.dll jinvoker.obj
-
-jinvoker.obj: jinvoker.cpp jinvokerExp.h Makefile
- cl /Fojinvoker.obj /DJINVOKEREEXPORT /c jinvoker.cpp
-
-invoked.class: invoked.java Makefile
- javac invoked.java
-
-invoker.exe: invoker.cs Makefile
- csc /unsafe invoker.cs
diff --git a/jdk/src/sample/share/vm/clr-jvm/README.txt b/jdk/src/sample/share/vm/clr-jvm/README.txt
deleted file mode 100644
index 52ed44e6d82..00000000000
--- a/jdk/src/sample/share/vm/clr-jvm/README.txt
+++ /dev/null
@@ -1,54 +0,0 @@
-This sample provides Java "Hello World" program that is invoked
-from C# application in the same process.
-
-The problem of direct call of the JVM API from CLR applications
-by PInvoke interface is the JVM API functions do not have static
-adresses, they need to be got by JNI_CreateJavaVM() call.
-The sample contains C++ libraty that wraps JVM API calls by the
-static functions that are called from the C# application by
-PInvoke interface.
-
-The sample contains the following files:
-
-Makefile - make file
-README.txt - this readme
-invoked.java - the invoked HelloWorld Java program
-invoker.cs - C# invoker application
-jinvoker.cpp - C++ wrapper
-jinvokerExp.h - wrapper library exports
-
-After the success making the following files are produced:
-
-invoked.class - the compiled HelloWorld class
-invoker.exe - the executable .NET program that invokes Java
-jinvoker.dll - the wrapper library
-
-The following environment needs to be set for the correct sample
-build and execution:
-
-INCLUDE must contain the paths to:
- 1. MS Visual C++ standard include
- 2. .NET SDK include
- 3. Java includes
- Example: %MSDEV%/VC98/Include;%DOTNET%/Include;%JAVA_HOME%/include;%JAVA_HOME%/include/win32
-
-LIB must contain the paths to:
- 1. MS Visual C++ standard libraries
- 2. .NET SDK libraries
- 3. jvm.dll
- Example: %MSDEV%/VC98/Lib;%DOTNET%/Lib;%JAVA_HOME%/jre/bin/client
-
-PATH must contain the paths to:
- 1. MS Visual C++ standard bin
- 2. MS Dev common bin
- 3. .NET SDK libraries
- 4. Java bin
- 5. jvm.dll
- Example: %MSDEV%/VC98/Bin;%MSDEV%/Common/MSDev98/Bin;%DOTNET%/Lib;%JAVA_HOME%/bin;%JAVA_HOME%/jre/bin/client;%PATH%
-
-To run the sample please do:
-
- invoker.exe invoked
-
-
---Dmitry Ryashchentsev
diff --git a/jdk/src/sample/share/vm/clr-jvm/invoked.java b/jdk/src/sample/share/vm/clr-jvm/invoked.java
deleted file mode 100644
index 307de742347..00000000000
--- a/jdk/src/sample/share/vm/clr-jvm/invoked.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-
-public class invoked {
- public static void main(String args[]) {
-
- // Print Hello to show we are in JVM
- System.out.println("Hello from Java!!!");
- System.exit(0);
- }
-}
diff --git a/jdk/src/sample/share/vm/clr-jvm/invoker.cs b/jdk/src/sample/share/vm/clr-jvm/invoker.cs
deleted file mode 100644
index 86555056213..00000000000
--- a/jdk/src/sample/share/vm/clr-jvm/invoker.cs
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
-*/
-
-using System;
-using System.Runtime.InteropServices;
-
-class jinvoker{
-
- public static int Main(string[] aArgs){
-
- // Print Hello to show we are in CLR
- Console.WriteLine("Hello from C#");
- if(aArgs.Length > 0)
- // invoke JVM
- return InvokeMain(aArgs[0]);
- else
- return -1;
- }
-
- // Link the JVM API functions and the wrappers
-
- [DllImport("jvm.dll")] public unsafe static extern int JNI_CreateJavaVM(void** ppVm, void** ppEnv, void* pArgs);
- [DllImport("jinvoker.dll")] public unsafe static extern int MakeJavaVMInitArgs( void** ppArgs );
- [DllImport("jinvoker.dll")] public unsafe static extern void FreeJavaVMInitArgs( void* pArgs );
- [DllImport("jinvoker.dll")] public unsafe static extern int FindClass( void* pEnv, String sClass, void** ppClass );
- [DllImport("jinvoker.dll")] public unsafe static extern int GetStaticMethodID( void* pEnv,
- void* pClass,
- String szName,
- String szArgs,
- void** ppMid);
-
- [DllImport("jinvoker.dll")] public unsafe static extern int NewObjectArray( void* pEnv,
- int nDimension,
- String sType,
- void** ppArray );
-
- [DllImport("jinvoker.dll")] public unsafe static extern int CallStaticVoidMethod( void* pEnv,
- void* pClass,
- void* pMid,
- void* pArgs);
-
- [DllImport("jinvoker.dll")] public unsafe static extern int DestroyJavaVM( void* pJVM );
-
- public unsafe static int InvokeMain( String sClass ){
-
- void* pJVM; // JVM struct
- void* pEnv; // JVM environment
- void* pVMArgs; // VM args
- void* pClass; // Class struct of the executed method
- void* pMethod; // The executed method struct
- void* pArgs; // The executed method arguments struct
-
- // Fill the pVMArgs structs
- MakeJavaVMInitArgs( &pVMArgs );
-
- // Create JVM
- int nRes = JNI_CreateJavaVM( &pJVM, &pEnv, pVMArgs );
- if( nRes == 0 ){
-
- // Find the executed method class
- if(FindClass( pEnv, sClass, &pClass) == 0 )
-
- // Find the executed method
- if( GetStaticMethodID( pEnv, pClass, "main", "([Ljava/lang/String;)V", &pMethod ) == 0 )
-
- // Create empty String[] array to pass to the main()
- if( NewObjectArray( pEnv, 0, "java/lang/String", &pArgs ) == 0 ){
-
- // Call main()
- nRes = CallStaticVoidMethod( pEnv, pClass, pMethod, pArgs );
- if( nRes != -1 )
- Console.WriteLine("Result:"+nRes);
- else
- Console.WriteLine("Exception");
-
- }else{
- Console.WriteLine("Error while making args array");
- nRes = -100;
- }
- else{
- Console.WriteLine("can not find method main(String[])");
- nRes = -101;
- }
- else{
- Console.WriteLine("can not find class:"+sClass);
- nRes = -102;
- }
-
- // Destroy the JVM
- DestroyJavaVM( pJVM );
-
- }else
- Console.WriteLine("Can not create Java VM");
-
- // Free the JVM args structs
- FreeJavaVMInitArgs(pVMArgs);
-
- return nRes;
- }
-}
diff --git a/jdk/src/sample/share/vm/clr-jvm/jinvoker.cpp b/jdk/src/sample/share/vm/clr-jvm/jinvoker.cpp
deleted file mode 100644
index a1d1f1abfd6..00000000000
--- a/jdk/src/sample/share/vm/clr-jvm/jinvoker.cpp
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This source code is provided to illustrate the usage of a given feature
- * or technique and has been deliberately simplified. Additional steps
- * required for a production-quality application, such as security checks,
- * input validation and proper error handling, might not be present in
- * this sample code.
- */
-
-
-#include