use of java.beans.PropertyChangeSupport in project jdk8u_jdk by JetBrains.
the class Test4985020 method main.
public static void main(String[] args) {
PropertyChangeSupport pcs = new PropertyChangeSupport(args);
VetoableChangeSupport vcs = new VetoableChangeSupport(args);
Test4985020 listener = new Test4985020();
//PropertyChangeSupport.addPropertyChangeListener(null, listener)
System.out.println("PropertyChangeSupport.addPropertyChangeListener(null, listener)");
try {
pcs.addPropertyChangeListener(null, listener);
pcs.firePropertyChange(NAME, null, null);
} catch (Throwable error) {
print(error);
}
//PropertyChangeSupport.removePropertyChangeListener(null, listener)
System.out.println("PropertyChangeSupport.removePropertyChangeListener(null, listener)");
try {
pcs.removePropertyChangeListener(null, listener);
pcs.firePropertyChange(NAME, null, null);
} catch (Throwable error) {
print(error);
}
//PropertyChangeSupport.getPropertyChangeListeners(null)
System.out.println("PropertyChangeSupport.getPropertyChangeListeners(null)");
try {
PropertyChangeListener[] pcls = pcs.getPropertyChangeListeners(null);
if (pcls == null) {
throw new Error("getPropertyChangeListener() returned null");
}
if (pcls.length != 0) {
throw new Error("getPropertyChangeListener() did not return an empty array");
}
} catch (Throwable error) {
print(error);
}
//PropertyChangeSupport.hasListeners(null)
System.out.println("PropertyChangeSupport.hasListeners(null)");
try {
pcs.hasListeners(null);
} catch (Throwable error) {
print(error);
}
//PropertyChangeSupport.hasListeners(null): with a generic listener
System.out.println("PropertyChangeSupport.hasListeners(null) with a generic listener");
try {
pcs.addPropertyChangeListener(listener);
if (!pcs.hasListeners(null)) {
throw new Error("hasListeners(null) returned false, but there was a generic listener");
}
} catch (Throwable error) {
print(error);
}
// reset
pcs = new PropertyChangeSupport(args);
//PropertyChangeSupport.hasListeners(null): with a specific listener
System.out.println("PropertyChangeSupport.hasListeners(null) with a specific listener");
try {
pcs.addPropertyChangeListener(NAME, listener);
if (pcs.hasListeners(null)) {
throw new Error("hasListeners(null) returned true, but there were no generic listeners - only a specific listener");
}
} catch (Throwable error) {
print(error);
}
//VetoableChangeSupport.addVetoableChangeListener(null, listener)
System.out.println("VetoableChangeSupport.addVetoableChangeListener(null, listener)");
try {
vcs.addVetoableChangeListener(null, listener);
vcs.fireVetoableChange(NAME, null, null);
} catch (Throwable error) {
print(error);
}
//VetoableChangeSupport.removeVetoableChangeListener(null, listener)
System.out.println("VetoableChangeSupport.removeVetoableChangeListener(null, listener)");
try {
vcs.removeVetoableChangeListener(null, listener);
vcs.fireVetoableChange(NAME, null, null);
} catch (Throwable error) {
print(error);
}
//VetoableChangeSupport.getVetoableChangeListeners(null)
System.out.println("VetoableChangeSupport.getVetoableChangeListeners(null)");
try {
VetoableChangeListener[] pcls = vcs.getVetoableChangeListeners(null);
if (pcls == null) {
throw new Error("getVetoableChangeListener() returned null");
}
if (pcls.length != 0) {
throw new Error("getVetoableChangeListener() did not return an empty array");
}
} catch (Throwable error) {
print(error);
}
//VetoableChangeSupport.hasListeners(null)
System.out.println("VetoableChangeSupport.hasListeners(null)");
try {
boolean result = vcs.hasListeners(null);
} catch (Throwable error) {
print(error);
}
//VetoableChangeSupport.hasListeners(null): with a generic listener
System.out.println("VetoableChangeSupport.hasListeners(null) with a generic listener");
try {
vcs.addVetoableChangeListener(listener);
if (!vcs.hasListeners(null)) {
throw new Error("hasListeners(null) returned false, but there was a generic listener");
}
} catch (Throwable error) {
print(error);
}
// reset
vcs = new VetoableChangeSupport(args);
//VetoableChangeSupport.hasListeners(null): with a specific listener
System.out.println("VetoableChangeSupport.hasListeners(null) with a specific listener");
try {
vcs.addVetoableChangeListener(NAME, listener);
if (vcs.hasListeners(null)) {
throw new Error("hasListeners(null) returned true, but there were no generic listeners - only a specific listener");
}
} catch (Throwable error) {
print(error);
}
if (failed) {
throw new Error("TEST FAILED");
}
}
use of java.beans.PropertyChangeSupport in project jdk8u_jdk by JetBrains.
the class MostRecentKeyValue method dispose.
// Default to 1-second timeout for all
// interrupted Threads to exit, and another
// 1 second for all stopped Threads to die.
/**
* Disposes of this AppContext, all of its top-level Frames, and
* all Threads and ThreadGroups contained within it.
*
* This method must be called from a Thread which is not contained
* within this AppContext.
*
* @exception IllegalThreadStateException if the current thread is
* contained within this AppContext
* @since 1.2
*/
public void dispose() throws IllegalThreadStateException {
// Check to be sure that the current Thread isn't in this AppContext
if (this.threadGroup.parentOf(Thread.currentThread().getThreadGroup())) {
throw new IllegalThreadStateException("Current Thread is contained within AppContext to be disposed.");
}
synchronized (this) {
if (this.state != State.VALID) {
// If already disposed or being disposed, bail.
return;
}
this.state = State.BEING_DISPOSED;
}
final PropertyChangeSupport changeSupport = this.changeSupport;
if (changeSupport != null) {
changeSupport.firePropertyChange(DISPOSED_PROPERTY_NAME, false, true);
}
// First, we post an InvocationEvent to be run on the
// EventDispatchThread which disposes of all top-level Frames and TrayIcons
final Object notificationLock = new Object();
Runnable runnable = new Runnable() {
public void run() {
Window[] windowsToDispose = Window.getOwnerlessWindows();
for (Window w : windowsToDispose) {
try {
w.dispose();
} catch (Throwable t) {
log.finer("exception occurred while disposing app context", t);
}
}
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
if (!GraphicsEnvironment.isHeadless() && SystemTray.isSupported()) {
SystemTray systemTray = SystemTray.getSystemTray();
TrayIcon[] trayIconsToDispose = systemTray.getTrayIcons();
for (TrayIcon ti : trayIconsToDispose) {
systemTray.remove(ti);
}
}
return null;
}
});
// Alert PropertyChangeListeners that the GUI has been disposed.
if (changeSupport != null) {
changeSupport.firePropertyChange(GUI_DISPOSED, false, true);
}
synchronized (notificationLock) {
// Notify caller that we're done
notificationLock.notifyAll();
}
}
};
synchronized (notificationLock) {
SunToolkit.postEvent(this, new InvocationEvent(Toolkit.getDefaultToolkit(), runnable));
try {
notificationLock.wait(DISPOSAL_TIMEOUT);
} catch (InterruptedException e) {
}
}
// Next, we post another InvocationEvent to the end of the
// EventQueue. When it's executed, we know we've executed all
// events in the queue.
runnable = new Runnable() {
public void run() {
synchronized (notificationLock) {
// Notify caller that we're done
notificationLock.notifyAll();
}
}
};
synchronized (notificationLock) {
SunToolkit.postEvent(this, new InvocationEvent(Toolkit.getDefaultToolkit(), runnable));
try {
notificationLock.wait(DISPOSAL_TIMEOUT);
} catch (InterruptedException e) {
}
}
// We are done with posting events, so change the state to disposed
synchronized (this) {
this.state = State.DISPOSED;
}
// Next, we interrupt all Threads in the ThreadGroup
this.threadGroup.interrupt();
// Note, the EventDispatchThread we've interrupted may dump an
// InterruptedException to the console here. This needs to be
// fixed in the EventDispatchThread, not here.
// Next, we sleep 10ms at a time, waiting for all of the active
// Threads in the ThreadGroup to exit.
long startTime = System.currentTimeMillis();
long endTime = startTime + THREAD_INTERRUPT_TIMEOUT;
while ((this.threadGroup.activeCount() > 0) && (System.currentTimeMillis() < endTime)) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
}
}
// Then, we stop any remaining Threads
this.threadGroup.stop();
// Next, we sleep 10ms at a time, waiting for all of the active
// Threads in the ThreadGroup to die.
startTime = System.currentTimeMillis();
endTime = startTime + THREAD_INTERRUPT_TIMEOUT;
while ((this.threadGroup.activeCount() > 0) && (System.currentTimeMillis() < endTime)) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
}
}
// Next, we remove this and all subThreadGroups from threadGroup2appContext
int numSubGroups = this.threadGroup.activeGroupCount();
if (numSubGroups > 0) {
ThreadGroup[] subGroups = new ThreadGroup[numSubGroups];
numSubGroups = this.threadGroup.enumerate(subGroups);
for (int subGroup = 0; subGroup < numSubGroups; subGroup++) {
threadGroup2appContext.remove(subGroups[subGroup]);
}
}
threadGroup2appContext.remove(this.threadGroup);
threadAppContext.set(null);
// Finally, we destroy the ThreadGroup entirely.
try {
this.threadGroup.destroy();
} catch (IllegalThreadStateException e) {
// Fired if not all the Threads died, ignore it and proceed
}
synchronized (table) {
// Clear out the Hashtable to ease garbage collection
this.table.clear();
}
numAppContexts.decrementAndGet();
mostRecentKeyValue = null;
}
use of java.beans.PropertyChangeSupport in project cubrid-manager by CUBRID.
the class PropertyChangeProvider method readObject.
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
listeners = new PropertyChangeSupport(this);
}
use of java.beans.PropertyChangeSupport in project azure-tools-for-java by Microsoft.
the class SparkSubmissionToolWindowView method createPartControl.
@Override
public void createPartControl(Composite parent) {
GridLayout layout = new GridLayout();
layout.numColumns = 2;
parent.setLayout(layout);
Composite composite = new Composite(parent, SWT.NONE);
layout = new GridLayout();
composite.setLayout(layout);
GridData gridData = new GridData();
gridData.verticalAlignment = SWT.TOP;
composite.setLayoutData(gridData);
stopButton = new Button(composite, SWT.PUSH);
stopButton.setToolTipText("Stop execution of current application");
stopButton.setImage(Activator.getImageDescriptor(CommonConst.StopIconPath).createImage());
stopButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent evt) {
DefaultLoader.getIdeHelper().executeOnPooledThread(new Runnable() {
@Override
public void run() {
if (!StringHelper.isNullOrWhiteSpace(connectionUrl)) {
AppInsightsClient.create(Messages.SparkSubmissionStopButtionClickEvent, null);
try {
HttpResponse deleteResponse = SparkBatchSubmission.getInstance().killBatchJob(connectionUrl + "/livy/batches", batchId);
if (deleteResponse.getCode() == 201 || deleteResponse.getCode() == 200) {
jobStatusManager.setJobKilled();
setInfo("========================Stop application successfully=======================");
} else {
setError(String.format("Error : Failed to stop spark application. error code : %d, reason : %s.", deleteResponse.getCode(), deleteResponse.getContent()));
}
} catch (IOException exception) {
setError("Error : Failed to stop spark application. exception : " + exception.toString());
}
}
}
});
}
});
openSparkUIButton = new Button(composite, SWT.PUSH);
openSparkUIButton.setToolTipText("Open the corresponding Spark UI page");
openSparkUIButton.setImage(Activator.getImageDescriptor(CommonConst.OpenSparkUIIconPath).createImage());
openSparkUIButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
try {
if (jobStatusManager.isApplicationGenerated()) {
String sparkApplicationUrl = String.format(yarnRunningUIUrlFormat, connectionUrl, jobStatusManager.getApplicationId());
PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL(sparkApplicationUrl));
}
} catch (Exception browseException) {
DefaultLoader.getUIHelper().showError("Failed to browse spark application yarn url", "Spark Submission");
}
}
});
gridData = new GridData();
gridData.horizontalAlignment = SWT.FILL;
gridData.verticalAlignment = SWT.FILL;
gridData.grabExcessVerticalSpace = true;
gridData.grabExcessHorizontalSpace = true;
outputPanel = new Browser(parent, SWT.BORDER);
outputPanel.setLayoutData(gridData);
PropertyChangeListener propertyChangeListener = new PropertyChangeListener() {
@Override
public void propertyChange(final PropertyChangeEvent evt) {
// if (ApplicationManager.getApplication().isDispatchThread()) {
changeSupportHandler(evt);
//// } else {
// try {
// SwingUtilities.invokeAndWait(new Runnable() {
// @Override
// public void run() {
// changeSupportHandler(evt);
// }
// }
// );
// } catch (InterruptedException e) {
// e.printStackTrace();
// } catch (InvocationTargetException e) {
// e.printStackTrace();
// }
// }
}
private void changeSupportHandler(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals("toolWindowText")) {
outputPanel.setText(evt.getNewValue().toString());
} else if (evt.getPropertyName().equals("isStopButtonEnable")) {
stopButton.setEnabled(Boolean.parseBoolean(evt.getNewValue().toString()));
} else if (evt.getPropertyName().equals("isBrowserButtonEnable")) {
openSparkUIButton.setEnabled(Boolean.parseBoolean(evt.getNewValue().toString()));
}
}
};
// outputPanel.addPropertyChangeListener(propertyChangeListener);
changeSupport = new PropertyChangeSupport(outputPanel);
changeSupport.addPropertyChangeListener(propertyChangeListener);
}
use of java.beans.PropertyChangeSupport in project azure-tools-for-java by Microsoft.
the class SparkSubmissionToolWindowProcessor method initialize.
public void initialize() {
ApplicationManager.getApplication().assertIsDispatchThread();
UISettings.getInstance().addUISettingsListener(new UISettingsListener() {
@Override
public void uiSettingsChanged(UISettings uiSettings) {
synchronized (this) {
for (IHtmlElement htmlElement : cachedInfo) {
htmlElement.ChangeTheme();
}
setToolWindowText(parserHtmlElementList(cachedInfo));
}
}
}, ApplicationManager.getApplication());
fontFace = jEditorPanel.getFont().getFamily();
JPanel jPanel = new JPanel();
jPanel.setLayout(new GridBagLayout());
jEditorPanel.setMargin(new Insets(0, 10, 0, 0));
JBScrollPane scrollPane = new JBScrollPane(jEditorPanel);
stopButton = new JButton(PluginUtil.getIcon(CommonConst.StopIconPath));
stopButton.setDisabledIcon(PluginUtil.getIcon(CommonConst.StopDisableIconPath));
stopButton.setEnabled(false);
stopButton.setToolTipText("stop execution of current application");
stopButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
DefaultLoader.getIdeHelper().executeOnPooledThread(new Runnable() {
@Override
public void run() {
if (clusterDetail != null) {
AppInsightsClient.create(HDInsightBundle.message("SparkSubmissionStopButtionClickEvent"), null);
try {
HttpResponse deleteResponse = SparkBatchSubmission.getInstance().killBatchJob(SparkSubmitHelper.getLivyConnectionURL(clusterDetail), batchId);
if (deleteResponse.getCode() == 201 || deleteResponse.getCode() == 200) {
jobStatusManager.setJobKilled();
setInfo("========================Stop application successfully=======================");
} else {
setError(String.format("Error : Failed to stop spark application. error code : %d, reason : %s.", deleteResponse.getCode(), deleteResponse.getContent()));
}
} catch (IOException exception) {
setError("Error : Failed to stop spark application. exception : " + exception.toString());
}
}
}
});
}
});
openSparkUIButton = new JButton(PluginUtil.getIcon(CommonConst.OpenSparkUIIconPath));
openSparkUIButton.setDisabledIcon(PluginUtil.getIcon(CommonConst.OpenSparkUIDisableIconPath));
openSparkUIButton.setEnabled(false);
openSparkUIButton.setToolTipText("open the corresponding Spark UI page");
openSparkUIButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (Desktop.isDesktopSupported()) {
try {
if (jobStatusManager.isApplicationGenerated()) {
String connectionURL = clusterDetail.getConnectionUrl();
String sparkApplicationUrl = clusterDetail.isEmulator() ? String.format(yarnRunningUIEmulatorUrlFormat, ((EmulatorClusterDetail) clusterDetail).getSparkHistoryEndpoint(), jobStatusManager.getApplicationId()) : String.format(yarnRunningUIUrlFormat, connectionURL, jobStatusManager.getApplicationId());
Desktop.getDesktop().browse(new URI(sparkApplicationUrl));
}
} catch (Exception browseException) {
DefaultLoader.getUIHelper().showError("Failed to browse spark application yarn url", "Spark Submission");
}
}
}
});
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS));
buttonPanel.add(stopButton);
buttonPanel.add(openSparkUIButton);
GridBagConstraints c00 = new GridBagConstraints();
c00.fill = GridBagConstraints.VERTICAL;
c00.weighty = 1;
c00.gridx = 0;
c00.gridy = 0;
jPanel.add(buttonPanel, c00);
GridBagConstraints c10 = new GridBagConstraints();
c10.fill = GridBagConstraints.BOTH;
c10.weightx = 1;
c10.weighty = 1;
c10.gridx = 1;
c10.gridy = 0;
jPanel.add(scrollPane, c10);
toolWindow.getComponent().add(jPanel);
jEditorPanel.setEditable(false);
jEditorPanel.setOpaque(false);
jEditorPanel.setEditorKit(JEditorPane.createEditorKitForContentType("text/html"));
jEditorPanel.addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
if (Desktop.isDesktopSupported()) {
try {
String protocol = e.getURL().getProtocol();
if (protocol.equals("https") || protocol.equals("http")) {
Desktop.getDesktop().browse(e.getURL().toURI());
} else if (protocol.equals("file")) {
String path = e.getURL().getFile();
File localFile = new File(path);
File parentFile = localFile.getParentFile();
if (parentFile.exists() && parentFile.isDirectory()) {
Desktop.getDesktop().open(parentFile);
}
}
} catch (Exception exception) {
DefaultLoader.getUIHelper().showError(exception.getMessage(), "Open Local Folder Error");
}
}
}
}
});
PropertyChangeListener propertyChangeListener = new PropertyChangeListener() {
@Override
public void propertyChange(final PropertyChangeEvent evt) {
if (ApplicationManager.getApplication().isDispatchThread()) {
changeSupportHandler(evt);
} else {
try {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
changeSupportHandler(evt);
}
});
} catch (InterruptedException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
private void changeSupportHandler(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals("toolWindowText")) {
jEditorPanel.setText(evt.getNewValue().toString());
} else if (evt.getPropertyName().equals("isStopButtonEnable")) {
stopButton.setEnabled(Boolean.parseBoolean(evt.getNewValue().toString()));
} else if (evt.getPropertyName().equals("isBrowserButtonEnable")) {
openSparkUIButton.setEnabled(Boolean.parseBoolean(evt.getNewValue().toString()));
}
}
};
jEditorPanel.addPropertyChangeListener(propertyChangeListener);
changeSupport = new PropertyChangeSupport(jEditorPanel);
changeSupport.addPropertyChangeListener(propertyChangeListener);
}
Aggregations