-package org.simantics.modeling.subscription;\r
-\r
-import java.util.List;\r
-import java.util.concurrent.RejectedExecutionException;\r
-import java.util.logging.Level;\r
-\r
-import org.eclipse.core.runtime.IProgressMonitor;\r
-import org.eclipse.core.runtime.IStatus;\r
-import org.eclipse.core.runtime.Status;\r
-import org.eclipse.core.runtime.jobs.Job;\r
-import org.simantics.ObjectIdentitySchedulingRule;\r
-import org.simantics.db.common.procedure.adapter.ListenerAdapter;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.history.HistoryException;\r
-import org.simantics.history.util.subscription.SubscriptionItem;\r
-import org.simantics.modeling.subscription.ModelHistoryCollector.ItemCollector;\r
-\r
-/**\r
- * Listener for {@link SubscriptionCollectionResult} request. Reloads\r
- * {@link ItemCollector} on every execution.\r
- */\r
-class VariableSetListener extends ListenerAdapter<SubscriptionCollectionResult> {\r
- /**\r
- * \r
- */\r
- private final ModelHistoryCollector modelHistoryCollector;\r
-\r
- /**\r
- * @param modelHistoryCollector\r
- */\r
- VariableSetListener(ModelHistoryCollector modelHistoryCollector) {\r
- this.modelHistoryCollector = modelHistoryCollector;\r
- }\r
-\r
- boolean disposed;\r
-\r
- @Override\r
- public void execute(final SubscriptionCollectionResult result) {\r
- Job job = new Job("Reloading history subscriptions") {\r
- @Override\r
- protected IStatus run(IProgressMonitor monitor) {\r
- try {\r
- if (VariableSetListener.this.modelHistoryCollector.itemCollector.isDisposed())\r
- return Status.OK_STATUS;\r
- if (!result.getStatus().isOK() && VariableSetListener.this.modelHistoryCollector.logger != null)\r
- VariableSetListener.this.modelHistoryCollector.logger.log(result.getStatus());\r
-\r
- // Load in specified thread.\r
- final IStatus[] status = { null };\r
- Runnable loader = new Runnable() {\r
- @Override\r
- public void run() {\r
- try {\r
- List<SubscriptionItem> sampledItems = ModelHistoryCollector.sampledSubscriptionItems(result.getSubscriptions());\r
- VariableSetListener.this.modelHistoryCollector.itemCollector.load( sampledItems );\r
- } catch (HistoryException e) {\r
- status[0] = new Status(IStatus.ERROR, "org.simantics.modeling", e.getLocalizedMessage(), e);\r
- if (VariableSetListener.this.modelHistoryCollector.logger != null)\r
- VariableSetListener.this.modelHistoryCollector.logger.log(status[0]);\r
- } catch (DatabaseException e) {\r
- VariableSetListener.this.modelHistoryCollector.log.log(Level.WARNING, "Unexpected failure in history variable collection request.", e);\r
- status[0] = new Status(IStatus.ERROR, "org.simantics.modeling", e.getLocalizedMessage(), e); \r
- }\r
- }\r
- };\r
- if (VariableSetListener.this.modelHistoryCollector.loadThread != null)\r
- VariableSetListener.this.modelHistoryCollector.loadThread.syncExec(loader);\r
- else\r
- loader.run();\r
-\r
- if (status[0] == null && VariableSetListener.this.modelHistoryCollector.loadCallback != null)\r
- VariableSetListener.this.modelHistoryCollector.loadCallback.run();\r
-\r
- return status[0] != null ? status[0] : Status.OK_STATUS;\r
- } catch (RejectedExecutionException e) {\r
- // IThreadWorkQueue.syncExec may produce this.\r
- // Usually this means the executor has been\r
- // disposed.\r
- return new Status(IStatus.INFO, "org.simantics.modeling", e.getLocalizedMessage(), e);\r
- } finally {\r
- VariableSetListener.this.modelHistoryCollector.initMutex.release();\r
- }\r
- }\r
- };\r
- job.setRule(new ObjectIdentitySchedulingRule(this.modelHistoryCollector));\r
- job.setUser(false);\r
- job.schedule();\r
- }\r
- \r
- public void dispose() {\r
- disposed = true;\r
- }\r
- \r
- @Override\r
- public void exception(Throwable t) {\r
- this.modelHistoryCollector.initMutex.release();\r
- this.modelHistoryCollector.log.log(Level.WARNING, "Unexpected failure in history variable collection request.", t);\r
- }\r
- \r
- @Override\r
- public boolean isDisposed() {\r
- return disposed;\r
- }\r
+package org.simantics.modeling.subscription;
+
+import java.util.List;
+import java.util.concurrent.RejectedExecutionException;
+import java.util.logging.Level;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.simantics.ObjectIdentitySchedulingRule;
+import org.simantics.db.common.procedure.adapter.ListenerAdapter;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.history.HistoryException;
+import org.simantics.history.util.subscription.SubscriptionItem;
+import org.simantics.modeling.subscription.ModelHistoryCollector.ItemCollector;
+
+/**
+ * Listener for {@link SubscriptionCollectionResult} request. Reloads
+ * {@link ItemCollector} on every execution.
+ */
+class VariableSetListener extends ListenerAdapter<SubscriptionCollectionResult> {
+ /**
+ *
+ */
+ private final ModelHistoryCollector modelHistoryCollector;
+
+ /**
+ * @param modelHistoryCollector
+ */
+ VariableSetListener(ModelHistoryCollector modelHistoryCollector) {
+ this.modelHistoryCollector = modelHistoryCollector;
+ }
+
+ boolean disposed;
+
+ @Override
+ public void execute(final SubscriptionCollectionResult result) {
+ Job job = new Job("Reloading history subscriptions") {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ if (VariableSetListener.this.modelHistoryCollector.itemCollector.isDisposed())
+ return Status.OK_STATUS;
+ if (!result.getStatus().isOK() && VariableSetListener.this.modelHistoryCollector.logger != null)
+ VariableSetListener.this.modelHistoryCollector.logger.log(result.getStatus());
+
+ // Load in specified thread.
+ final IStatus[] status = { null };
+ Runnable loader = new Runnable() {
+ @Override
+ public void run() {
+ try {
+ List<SubscriptionItem> sampledItems = ModelHistoryCollector.sampledSubscriptionItems(result.getSubscriptions());
+ VariableSetListener.this.modelHistoryCollector.itemCollector.load( sampledItems );
+ } catch (HistoryException e) {
+ status[0] = new Status(IStatus.ERROR, "org.simantics.modeling", e.getLocalizedMessage(), e);
+ if (VariableSetListener.this.modelHistoryCollector.logger != null)
+ VariableSetListener.this.modelHistoryCollector.logger.log(status[0]);
+ } catch (DatabaseException e) {
+ VariableSetListener.this.modelHistoryCollector.log.log(Level.WARNING, "Unexpected failure in history variable collection request.", e);
+ status[0] = new Status(IStatus.ERROR, "org.simantics.modeling", e.getLocalizedMessage(), e);
+ }
+ }
+ };
+ if (VariableSetListener.this.modelHistoryCollector.loadThread != null)
+ VariableSetListener.this.modelHistoryCollector.loadThread.syncExec(loader);
+ else
+ loader.run();
+
+ if (status[0] == null && VariableSetListener.this.modelHistoryCollector.loadCallback != null)
+ VariableSetListener.this.modelHistoryCollector.loadCallback.run();
+
+ return status[0] != null ? status[0] : Status.OK_STATUS;
+ } catch (RejectedExecutionException e) {
+ // IThreadWorkQueue.syncExec may produce this.
+ // Usually this means the executor has been
+ // disposed.
+ return new Status(IStatus.INFO, "org.simantics.modeling", e.getLocalizedMessage(), e);
+ } finally {
+ VariableSetListener.this.modelHistoryCollector.initMutex.release();
+ }
+ }
+ };
+ job.setRule(new ObjectIdentitySchedulingRule(this.modelHistoryCollector));
+ job.setUser(false);
+ job.schedule();
+ }
+
+ public void dispose() {
+ disposed = true;
+ }
+
+ @Override
+ public void exception(Throwable t) {
+ this.modelHistoryCollector.initMutex.release();
+ this.modelHistoryCollector.log.log(Level.WARNING, "Unexpected failure in history variable collection request.", t);
+ }
+
+ @Override
+ public boolean isDisposed() {
+ return disposed;
+ }
}
\ No newline at end of file