Kartom

UITask.java

Oct 25th, 2024
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.11 KB | Source Code | 0 0
  1. package com.pnfsoftware.jeb.rcpclient.extensions.ui;
  2.  
  3. /* loaded from: jeb.apk:com/pnfsoftware/rcpclient/extensions/ui/UITask.class */
  4. public class UITask<T> {
  5.     private static final com.pnfsoftware.jeb.util.logging.ILogger logger = com.pnfsoftware.jeb.util.logging.GlobalLog.getLogger(com.pnfsoftware.jeb.rcpclient.extensions.ui.UITask.class);
  6.     private java.lang.String taskName;
  7.     private long checkTimeoutMs = 200;
  8.     private java.lang.Runnable runnable;
  9.     private java.util.concurrent.Callable<T> callable;
  10.     private T result;
  11.  
  12.     public UITask(java.util.concurrent.ExecutorService execsvc, java.lang.String taskName, java.lang.Runnable runnable) {
  13.         this.taskName = taskName;
  14.         this.runnable = runnable;
  15.     }
  16.  
  17.     public UITask(java.util.concurrent.ExecutorService execsvc, java.lang.String taskName, java.util.concurrent.Callable<T> callable) {
  18.         this.taskName = taskName;
  19.         this.callable = callable;
  20.     }
  21.  
  22.     public void setCheckTimeout(long millis) {
  23.         this.checkTimeoutMs = millis;
  24.     }
  25.  
  26.     public long setCheckTimeout() {
  27.         return this.checkTimeoutMs;
  28.     }
  29.  
  30.     public T getResult() {
  31.         return this.result;
  32.     }
  33.  
  34.     public void run(com.pnfsoftware.jeb.rcpclient.extensions.ui.ITaskProgressMonitor monitor) throws java.lang.reflect.InvocationTargetException, java.lang.InterruptedException {
  35.         com.pnfsoftware.jeb.util.concurrent.ThreadEx<T> t;
  36.         if (this.taskName != null) {
  37.             monitor.setTaskName(this.taskName);
  38.         }
  39.         com.pnfsoftware.jeb.util.base.IProgressCallback callback = new com.pnfsoftware.jeb.rcpclient.extensions.ui.UITask$1(this, monitor);
  40.         if (this.callable instanceof com.pnfsoftware.jeb.util.base.CallableWithProgressCallback) {
  41.             ((com.pnfsoftware.jeb.util.base.CallableWithProgressCallback) this.callable).setCallback(callback);
  42.         }
  43.         if (this.runnable instanceof com.pnfsoftware.jeb.util.base.RunnableWithProgressCallback) {
  44.             ((com.pnfsoftware.jeb.util.base.RunnableWithProgressCallback) this.runnable).setCallback(callback);
  45.         }
  46.         if (this.runnable != null) {
  47.             t = new com.pnfsoftware.jeb.util.concurrent.ThreadEx<>(this.runnable);
  48.         } else {
  49.             t = new com.pnfsoftware.jeb.util.concurrent.ThreadEx<>(this.callable);
  50.         }
  51.         t.start();
  52.         while (true) {
  53.             try {
  54.                 if (this.runnable != null) {
  55.                     t.get(this.checkTimeoutMs);
  56.                 } else {
  57.                     this.result = t.get(this.checkTimeoutMs);
  58.                 }
  59.             } catch (java.lang.InterruptedException e) {
  60.                 throw e;
  61.             } catch (java.util.concurrent.ExecutionException e2) {
  62.                 throw new java.lang.reflect.InvocationTargetException(e2.getCause());
  63.             } catch (java.util.concurrent.TimeoutException unused) {
  64.             }
  65.             if (t.isAlive()) {
  66.                 if (monitor.isCanceled()) {
  67.                     t.interrupt();
  68.                 }
  69.             } else {
  70.                 return;
  71.             }
  72.         }
  73.     }
  74. }
Tags: JEB
Advertisement
Add Comment
Please, Sign In to add comment