本文整理汇总了Java中java.util.prefs.NodeChangeListener类的典型用法代码示例。如果您正苦于以下问题:Java NodeChangeListener类的具体用法?Java NodeChangeListener怎么用?Java NodeChangeListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NodeChangeListener类属于java.util.prefs包,在下文中一共展示了NodeChangeListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fireNodeEvents
import java.util.prefs.NodeChangeListener; //导入依赖的package包/类
private void fireNodeEvents(List<EventBag<NodeChangeListener, NodeChangeEvent>> events) {
if (noEvents) {
return;
}
for(EventBag<NodeChangeListener, NodeChangeEvent> bag : events) {
for(NodeChangeEvent event : bag.getEvents()) {
for(NodeChangeListener l : bag.getListeners()) {
try {
if ((event instanceof NodeChangeEventExt) && ((NodeChangeEventExt) event).isRemovalEvent()) {
l.childRemoved(event);
} else {
l.childAdded(event);
}
} catch (Throwable t) {
LOG.log(Level.WARNING, null, t);
}
}
}
}
}
示例2: testNodeAdded
import java.util.prefs.NodeChangeListener; //导入依赖的package包/类
protected ScheduledFuture<?> testNodeAdded(final NodeChangeListener listener,
final Preferences parent, final String childName, final int count) {
final ArgumentCaptor<NodeChangeEvent> captor = ArgumentCaptor.forClass(NodeChangeEvent.class);
final Runnable task = new Runnable() {
@Override public void run() {
verify(listener, times(count)).childAdded(captor.capture());
final NodeChangeEvent event = captor.getValue();
assertEquals(event.getParent(), parent);
assertEquals(event.getChild().name(), childName);
}
};
return schedule(task);
}
示例3: testNodeRemoved
import java.util.prefs.NodeChangeListener; //导入依赖的package包/类
protected ScheduledFuture<?> testNodeRemoved(final NodeChangeListener listener,
final Preferences parent, final String childName, final int count) {
final ArgumentCaptor<NodeChangeEvent> captor = ArgumentCaptor.forClass(NodeChangeEvent.class);
final Runnable task = new Runnable() {
@Override public void run() {
verify(listener, times(count)).childRemoved(captor.capture());
final NodeChangeEvent event = captor.getValue();
assertEquals(event.getParent(), parent);
assertEquals(event.getChild().name(), childName);
}
};
return schedule(task);
}
示例4: shouldTriggerNodeAdded
import java.util.prefs.NodeChangeListener; //导入依赖的package包/类
@Test(dataProvider = "chroot", groups = {"prefs", "hierarchy", "notifications"},
dependsOnGroups = "factory", timeOut = 1000L)
public void shouldTriggerNodeAdded(Preferences prefs) throws Exception {
final Preferences watched = prefs.node("watched");
final NodeChangeListener listener = nodeListener(watched);
final Preferences n1 = watched.node("n1");
testNodeAdded(listener, watched, n1.name(), 1).get();
watched.node("n1"); // not a new node, so the invocation count should stay the same
prefs.node("n0"); // shouldn't trigger anything for our listener, as it's a parent event
testNodeAdded(listener, watched, n1.name(), 1).get();
final Preferences n2 = watched.node("n2");
testNodeAdded(listener, watched, n2.name(), 2).get();
watched.node("n3/nested");
testNodeAdded(listener, watched, "n3", 3).get();
}
示例5: shouldTriggerNodeRemoved
import java.util.prefs.NodeChangeListener; //导入依赖的package包/类
@Test(dataProvider = "chroot", groups = {"prefs", "hierarchy", "notifications"},
dependsOnMethods = "shouldTriggerNodeAdded", timeOut = 1000L)
public void shouldTriggerNodeRemoved(Preferences prefs) throws Exception {
final Preferences watched = prefs.node("watched");
final NodeChangeListener listener = nodeListener(watched);
watched.node("n1").removeNode();
testNodeRemoved(listener, watched, "n1", 1).get();
watched.node("n2").removeNode();
testNodeRemoved(listener, watched, "n2", 2).get();
watched.node("n3/nested").removeNode();
testNodeRemoved(listener, watched, "n2", 2).get();
watched.node("n3").removeNode();
testNodeRemoved(listener, watched, "n3", 3).get();
}
示例6: testAddNodeChangeListener
import java.util.prefs.NodeChangeListener; //导入依赖的package包/类
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "addNodeChangeListener",
args = {java.util.prefs.NodeChangeListener.class}
)
public void testAddNodeChangeListener() throws BackingStoreException {
MockNodeChangeListener mncl = new MockNodeChangeListener();
parent.addNodeChangeListener(mncl);
pref.node("test");
pref.flush();
parent.flush();
assertFalse(mncl.isAdded());
assertFalse(mncl.isRemoved());
pref.removeNode();
parent.flush();
assertFalse(mncl.isAdded());
assertTrue(mncl.isRemoved());
parent.node("new node");
parent.flush();
assertTrue(mncl.isAdded());
assertTrue(mncl.isRemoved());
}
示例7: testRemoveNodeChangeListener
import java.util.prefs.NodeChangeListener; //导入依赖的package包/类
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "removeNodeChangeListener",
args = {java.util.prefs.NodeChangeListener.class}
)
public void testRemoveNodeChangeListener() throws BackingStoreException {
MockNodeChangeListener mncl = new MockNodeChangeListener();
parent.addNodeChangeListener(mncl);
pref.node("test");
pref.flush();
parent.flush();
assertFalse(mncl.isAdded());
assertFalse(mncl.isRemoved());
parent.removeNodeChangeListener(mncl);
pref.removeNode();
parent.flush();
assertFalse(mncl.isAdded());
assertFalse(mncl.isRemoved());
parent.node("new node");
parent.flush();
assertFalse(mncl.isAdded());
assertFalse(mncl.isRemoved());
}
示例8: removeNodeChangeListener
import java.util.prefs.NodeChangeListener; //导入依赖的package包/类
@Override
public void removeNodeChangeListener(NodeChangeListener ncl) {
try {
super.removeNodeChangeListener(ncl);
} catch (IllegalArgumentException e) {
// ignore, see #143581
}
}
示例9: sync
import java.util.prefs.NodeChangeListener; //导入依赖的package包/类
@Override
public void sync() throws BackingStoreException {
ArrayList<EventBag<PreferenceChangeListener, PreferenceChangeEvent>> prefEvents = new ArrayList<EventBag<PreferenceChangeListener, PreferenceChangeEvent>>();
ArrayList<EventBag<NodeChangeListener, NodeChangeEvent>> nodeEvents = new ArrayList<EventBag<NodeChangeListener, NodeChangeEvent>>();
synchronized (tree.treeLock()) {
_sync(prefEvents, nodeEvents);
}
fireNodeEvents(nodeEvents);
firePrefEvents(prefEvents);
}
示例10: ProxyPreferences
import java.util.prefs.NodeChangeListener; //导入依赖的package包/类
private ProxyPreferences(ProxyPreferences parent, MemoryPreferences memoryPref, Preferences delegate) {
this.parent = parent;
this.delegateRoot = memoryPref;
this.delegate = delegate == null ? memoryPref.getPreferences() : delegate;
weakPrefListener = WeakListeners.create(PreferenceChangeListener.class, this, delegate);
this.delegate.addPreferenceChangeListener(weakPrefListener);
weakNodeListener = WeakListeners.create(NodeChangeListener.class, this, delegate);
this.delegate.addNodeChangeListener(weakNodeListener);
}
示例11: concurrencyTest
import java.util.prefs.NodeChangeListener; //导入依赖的package包/类
@Test(dataProvider = "chroot", groups = {"prefs", "concurrency"},
dependsOnGroups = {"hierarchy", "kv"}, invocationCount = 5, threadPoolSize = 3, timeOut = 3000L)
public void concurrencyTest(Preferences prefs) throws Exception {
final Preferences child = prefs.node(UUID.randomUUID().toString());
final String key = UUID.randomUUID().toString();
final NodeChangeListener nodeListener = nodeListener(child);
final PreferenceChangeListener prefListener = prefListener(child);
prefs.putInt(key, 12);
final Preferences grandson = child.node("grandson");
ScheduledFuture<?> nodeAdded = testNodeAdded(nodeListener, child, grandson.name(), 1);
child.putBoolean(key, true);
ScheduledFuture<?> prefSet = testPrefChange(prefListener, child, key, "true", 1);
assertEquals(prefs.getInt(key, 0), 12);
assertTrue(child.getBoolean(key, false));
grandson.removeNode();
ScheduledFuture<?> nodeRemoved = testNodeRemoved(nodeListener, child, grandson.name(), 1);
prefSet.get();
child.remove(key);
child.removeNode();
assertEquals(prefs.getInt(key, 0), 12);
nodeAdded.get();
nodeRemoved.get();
testPrefChange(prefListener, child, key, null, 2).get();
}
示例12: shouldSyncNodeChanges
import java.util.prefs.NodeChangeListener; //导入依赖的package包/类
@Test(dataProvider = "chroot", groups = {"prefs", "backing-store"}, dependsOnGroups = {"hierarchy", "kv"})
public void shouldSyncNodeChanges(Preferences prefs) throws Exception {
assertFalse(prefs.nodeExists("x"));
assertFalse(childExistsInBackingStore(prefs, "x"));
final Preferences x = prefs.node("x");
// prefs.flush();
assertTrue(childExistsInBackingStore(prefs, "x"));
final NodeChangeListener listener = nodeListener(x);
createInBackingStore(x, "y");
assertTrue(childExistsInBackingStore(x, "y"));
final ScheduledFuture<?> nodeAdded = testNodeAdded(listener, x, "y", 1);
// prefs.sync();
assertTrue(x.nodeExists("y"));
nodeAdded.get();
assertTrue(x.nodeExists("y"));
assertTrue(childExistsInBackingStore(x, "y"));
removeChildFromBackingStore(x, "y");
assertFalse(childExistsInBackingStore(x, "y"));
final ScheduledFuture<?> nodeRemoved = testNodeRemoved(listener, x, "y", 1);
// prefs.sync();
assertFalse(x.nodeExists("y"));
nodeRemoved.get();
x.removeNode();
// prefs.flush();
assertFalse(childExistsInBackingStore(prefs, "x"));
}
示例13: addNodeChangeListener
import java.util.prefs.NodeChangeListener; //导入依赖的package包/类
@Override
public void addNodeChangeListener(NodeChangeListener ncl) {
synchronized (tree.treeLock()) {
nodeListeners.add(ncl);
}
}
示例14: removeNodeChangeListener
import java.util.prefs.NodeChangeListener; //导入依赖的package包/类
@Override
public void removeNodeChangeListener(NodeChangeListener ncl) {
synchronized (tree.treeLock()) {
nodeListeners.remove(ncl);
}
}
示例15: node
import java.util.prefs.NodeChangeListener; //导入依赖的package包/类
private ProxyPreferencesImpl node(String pathName, boolean create, List<EventBag<NodeChangeListener, NodeChangeEvent>> events) {
if (pathName.length() > 0 && pathName.charAt(0) == '/') { //NOI18N
// absolute path, if this is not the root then find the root
// and pass the call to it
if (parent != null) {
Preferences root = this;
while (root.parent() != null) {
root = root.parent();
}
return ((ProxyPreferencesImpl) root).node(pathName, create, events);
} else {
// this is the root, change the pathName to a relative path and proceed
pathName = pathName.substring(1);
}
}
if (pathName.length() > 0) {
String childName;
String pathFromChild;
int idx = pathName.indexOf('/'); //NOI18N
if (idx != -1) {
childName = pathName.substring(0, idx);
pathFromChild = pathName.substring(idx + 1);
} else {
childName = pathName;
pathFromChild = null;
}
ProxyPreferencesImpl child = children.get(childName);
if (child == null) {
if (removedChildren.contains(childName) && !create) {
// this child has been removed
return null;
}
Preferences childDelegate = null;
try {
if (delegate != null && delegate.nodeExists(childName)) {
childDelegate = delegate.node(childName);
}
} catch (BackingStoreException bse) {
// ignore
}
if (childDelegate != null || create) {
child = tree.get(this, childName, childDelegate);
children.put(childName, child);
removedChildren.remove(childName);
// fire event if we really created the new child node
if (childDelegate == null) {
EventBag<NodeChangeListener, NodeChangeEvent> bag = new EventBag<NodeChangeListener, NodeChangeEvent>();
bag.addListeners(nodeListeners);
bag.addEvent(new NodeChangeEventExt(this, child, false));
events.add(bag);
}
} else {
// childDelegate == null && !create
return null;
}
} else {
assert !child.removed;
}
return pathFromChild != null ? child.node(pathFromChild, create, events) : child;
} else {
return this;
}
}