Search in sources :

Example 1 with AEThread2

use of com.biglybt.core.util.AEThread2 in project BiglyBT by BiglySoftware.

the class Win32UIEnhancer method initMainShell.

public static void initMainShell(Shell shell) {
    // Canvas canvas = new Canvas(shell, SWT.NO_BACKGROUND | SWT.NO_TRIM);
    // canvas.setVisible(false);
    Shell subshell = new Shell(shell);
    try {
        messageCallback = constCallBack.newInstance(new Object[] { Win32UIEnhancer.class, "messageProc2", 4 });
        Object oHandle = subshell.getClass().getField("handle").get(subshell);
        oldProc = ((Number) mGetWindowLongPtr.invoke(null, new Object[] { oHandle, OS_GWLP_WNDPROC })).longValue();
        if (useLong) {
            Number n = (Number) mCallback_getAddress.invoke(messageCallback, new Object[] {});
            messageProcLong = n.longValue();
            if (messageProcLong != 0) {
                mSetWindowLongPtr.invoke(null, new Object[] { oHandle, OS_GWLP_WNDPROC, messageProcLong });
            }
        } else {
            Number n = (Number) mCallback_getAddress.invoke(messageCallback, new Object[] {});
            messageProcInt = n.intValue();
            if (messageProcInt != 0) {
                mSetWindowLongPtr.invoke(null, new Object[] { oHandle, OS_GWLP_WNDPROC, messageProcInt });
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    new AEThread2("Async:USB") {

        @Override
        public void run() {
            if (Constants.isWindows7OrHigher) {
                String version = AEWin32Manager.getAccessor(false).getVersion();
                if (Constants.compareVersions("1.21", version) > 0) {
                    return;
                }
            }
            Map<File, Map> drives = AEWin32Manager.getAccessor(false).getAllDrives();
            if (drives != null) {
                for (File file : drives.keySet()) {
                    Map driveInfo = drives.get(file);
                    boolean isWritableUSB = AEWin32Manager.getAccessor(false).isUSBDrive(driveInfo);
                    driveInfo.put("isWritableUSB", isWritableUSB);
                    DriveDetectorFactory.getDeviceDetector().driveDetected(file, driveInfo);
                }
            }
        }
    }.start();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) Map(java.util.Map) File(java.io.File) AEThread2(com.biglybt.core.util.AEThread2)

Example 2 with AEThread2

use of com.biglybt.core.util.AEThread2 in project BiglyBT by BiglySoftware.

the class CoreWaiterSWT method waitForCore.

public static void waitForCore(final TriggerInThread triggerInThread, final CoreRunningListener l) {
    CoreFactory.addCoreRunningListener(new CoreRunningListener() {

        @Override
        public void coreRunning(final Core core) {
            if (triggerInThread == TriggerInThread.ANY_THREAD) {
                l.coreRunning(core);
            } else if (triggerInThread == TriggerInThread.NEW_THREAD) {
                new AEThread2("CoreWaiterInvoke", true) {

                    @Override
                    public void run() {
                        l.coreRunning(core);
                    }
                }.start();
            }
            Utils.execSWTThread(new AERunnable() {

                @Override
                public void runSupport() {
                    // TODO: Need to detect cancel (can't rely on shell status since it may never open)
                    if (shell != null && !shell.isDisposed()) {
                        shell.dispose();
                        shell = null;
                    }
                    if (triggerInThread == TriggerInThread.SWT_THREAD) {
                        l.coreRunning(core);
                    }
                }
            });
        }
    });
    if (!CoreFactory.isCoreRunning()) {
        if (DEBUG) {
            System.out.println("NOT AVAIL FOR " + Debug.getCompressedStackTrace());
        }
        Utils.execSWTThread(new AERunnable() {

            @Override
            public void runSupport() {
                showWaitWindow();
            }
        });
    } else if (DEBUG) {
        System.out.println("NO NEED TO WAIT.. CORE AVAIL! " + Debug.getCompressedStackTrace());
    }
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) CoreRunningListener(com.biglybt.core.CoreRunningListener) AEThread2(com.biglybt.core.util.AEThread2) Core(com.biglybt.core.Core)

Example 3 with AEThread2

use of com.biglybt.core.util.AEThread2 in project BiglyBT by BiglySoftware.

the class TranscodePipe method setMaxBytesPerSecond.

public void setMaxBytesPerSecond(int max) {
    if (max == max_bytes_per_sec) {
        return;
    }
    max_bytes_per_sec = max;
    synchronized (this) {
        if (refiller == null) {
            refiller = new AEThread2("refiller", true) {

                @Override
                public void run() {
                    int count = 0;
                    while (!destroyed) {
                        if (max_bytes_per_sec == 0) {
                            synchronized (TranscodePipe.this) {
                                if (max_bytes_per_sec == 0) {
                                    refiller = null;
                                    break;
                                }
                            }
                        }
                        count++;
                        bytes_available += max_bytes_per_sec / 10;
                        if (count % 10 == 0) {
                            bytes_available += max_bytes_per_sec % 10;
                        }
                        try {
                            Thread.sleep(100);
                        } catch (Throwable e) {
                            Debug.printStackTrace(e);
                            break;
                        }
                    }
                }
            };
            refiller.start();
        }
    }
}
Also used : AEThread2(com.biglybt.core.util.AEThread2)

Example 4 with AEThread2

use of com.biglybt.core.util.AEThread2 in project BiglyBT by BiglySoftware.

the class TranscodePipe method handleRAF.

protected void handleRAF(final OutputStream os, final long position, final long length) {
    new AEThread2("TranscodePipe:c", true) {

        @Override
        public void run() {
            RandomAccessFile raf = null;
            try {
                raf = reserveRAF();
                long pos = position;
                long rem = length;
                while (!destroyed && rem > 0) {
                    int limit;
                    if (paused) {
                        Thread.sleep(250);
                        limit = 1;
                    } else {
                        if (max_bytes_per_sec > 0) {
                            limit = bytes_available;
                            if (limit <= 0) {
                                Thread.sleep(25);
                                continue;
                            }
                            limit = Math.min(BUFFER_SIZE, limit);
                        } else {
                            limit = BUFFER_SIZE;
                        }
                        limit = (int) Math.min(rem, limit);
                    }
                    int read_length = 0;
                    int buffer_start = 0;
                    byte[] buffer = null;
                    synchronized (TranscodePipe.this) {
                        int c_num = 0;
                        Iterator<bufferCache> it = buffer_cache.iterator();
                        while (it.hasNext()) {
                            bufferCache b = it.next();
                            long rel_offset = pos - b.offset;
                            if (rel_offset >= 0) {
                                byte[] data = b.data;
                                long avail = data.length - rel_offset;
                                if (avail > 0) {
                                    read_length = (int) Math.min(avail, limit);
                                    buffer = data;
                                    buffer_start = (int) rel_offset;
                                    if (c_num > 0) {
                                        it.remove();
                                        buffer_cache.addFirst(b);
                                    }
                                    break;
                                }
                            }
                            c_num++;
                        }
                        if (buffer == null) {
                            buffer = new byte[limit];
                            raf.seek(pos);
                            read_length = raf.read(buffer);
                            if (read_length != limit) {
                                Debug.out("eh?");
                                throw (new IOException("Inconsistent"));
                            }
                            bufferCache b = new bufferCache(pos, buffer);
                            // System.out.println( "adding to cache: o_offset=" + pos + ", size=" + limit );
                            buffer_cache.addFirst(b);
                            buffer_cache_size += limit;
                            while (buffer_cache_size > BUFFER_CACHE_SIZE) {
                                b = buffer_cache.removeLast();
                                buffer_cache_size -= b.data.length;
                            }
                        }
                    }
                    if (read_length <= 0) {
                        break;
                    }
                    rem -= read_length;
                    pos += read_length;
                    if (max_bytes_per_sec > 0) {
                        bytes_available -= read_length;
                    }
                    os.write(buffer, buffer_start, read_length);
                    write_speed.addValue(read_length);
                }
                os.flush();
            } catch (Throwable e) {
                if (raf != null) {
                    try {
                        synchronized (TranscodePipe.this) {
                            raf.seek(0);
                            raf.read(new byte[1]);
                        }
                    } catch (Throwable f) {
                        reportError(e);
                    }
                }
            } finally {
                try {
                    os.close();
                } catch (Throwable e) {
                }
                if (raf != null) {
                    releaseRAF(raf);
                }
            }
        }
    }.start();
}
Also used : RandomAccessFile(java.io.RandomAccessFile) Iterator(java.util.Iterator) IOException(java.io.IOException) AEThread2(com.biglybt.core.util.AEThread2)

Example 5 with AEThread2

use of com.biglybt.core.util.AEThread2 in project BiglyBT by BiglySoftware.

the class SubscriptionListWindow method startChecking.

private void startChecking() {
    action.setText(MessageText.getString("subscriptions.listwindow.subscribe"));
    action.setEnabled(false);
    try {
        SubscriptionManager subs_man = SubscriptionManagerFactory.getSingleton();
        if (useCachedSubs) {
            Subscription[] subs = subs_man.getKnownSubscriptions(torrent_hash);
            complete(torrent_hash, subs);
        } else {
            lookup = subs_man.lookupAssociations(torrent_hash, display_name, networks, this);
            lookup.setTimeout(1 * 60 * 1000);
        }
        loadingDone = false;
        AEThread2 progressMover = new AEThread2("progressMover", true) {

            @Override
            public void run() {
                final int[] waitTime = new int[1];
                waitTime[0] = 100;
                while (!loadingDone) {
                    if (display != null && !display.isDisposed()) {
                        display.asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                if (loadingProgress != null && !loadingProgress.isDisposed()) {
                                    int currentSelection = loadingProgress.getSelection() + 1;
                                    loadingProgress.setSelection(currentSelection);
                                    if (currentSelection > (loadingProgress.getMaximum()) * 80 / 100) {
                                        waitTime[0] = 300;
                                    }
                                    if (currentSelection > (loadingProgress.getMaximum()) * 90 / 100) {
                                        waitTime[0] = 1000;
                                    }
                                } else {
                                    loadingDone = true;
                                }
                            }
                        });
                    }
                    try {
                        Thread.sleep(waitTime[0]);
                    // Thread.sleep(100);
                    } catch (Exception e) {
                        loadingDone = true;
                    }
                }
            }
        };
        progressMover.start();
    } catch (Exception e) {
        failed(null, null);
    }
    animatedImage.start();
    mainLayout.topControl = loadingPanel;
}
Also used : SubscriptionManager(com.biglybt.core.subs.SubscriptionManager) Subscription(com.biglybt.core.subs.Subscription) AEThread2(com.biglybt.core.util.AEThread2) SubscriptionException(com.biglybt.core.subs.SubscriptionException)

Aggregations

AEThread2 (com.biglybt.core.util.AEThread2)20 File (java.io.File)6 PluginInterface (com.biglybt.pif.PluginInterface)5 Map (java.util.Map)5 GridData (org.eclipse.swt.layout.GridData)4 HashMap (java.util.HashMap)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 DiskManagerFileInfoURL (com.biglybt.core.download.DiskManagerFileInfoURL)2 MessageText (com.biglybt.core.internat.MessageText)2 LogEvent (com.biglybt.core.logging.LogEvent)2 AESemaphore (com.biglybt.core.util.AESemaphore)2 PluginListener (com.biglybt.pif.PluginListener)2 IPCInterface (com.biglybt.pif.ipc.IPCInterface)2 Update (com.biglybt.pif.update.Update)2 ResourceDownloader (com.biglybt.pif.utils.resourcedownloader.ResourceDownloader)2 ResourceDownloaderAdapter (com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderAdapter)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 URL (java.net.URL)2 Button (org.eclipse.swt.widgets.Button)2