use of com.biglybt.core.CoreLifecycleAdapter in project BiglyBT by BiglySoftware.
the class ViewQuickConfig method addTemporaryRates.
private void addTemporaryRates(Composite composite) {
Group temp_rates = new Group(composite, SWT.NULL);
Messages.setLanguageText(temp_rates, "label.temporary.rates");
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 4;
Utils.setLayoutData(temp_rates, gridData);
GridLayout layout = new GridLayout(10, false);
layout.marginWidth = 0;
layout.marginHeight = 0;
temp_rates.setLayout(layout);
// label = new Label(temp_rates, SWT.NULL);
// Messages.setLanguageText( label, "label.temporary.rates" );
Label label = new Label(temp_rates, SWT.NULL);
gridData = new GridData();
gridData.horizontalIndent = 4;
Utils.setLayoutData(label, gridData);
Messages.setLanguageText(label, "label.upload.kbps", new String[] { DisplayFormatters.getRateUnit(DisplayFormatters.UNIT_KB) });
final IntParameter tempULRate = new IntParameter(temp_rates, "global.download.rate.temp.kbps", 0, Integer.MAX_VALUE);
label = new Label(temp_rates, SWT.NULL);
Messages.setLanguageText(label, "label.download.kbps", new String[] { DisplayFormatters.getRateUnit(DisplayFormatters.UNIT_KB) });
final IntParameter tempDLRate = new IntParameter(temp_rates, "global.upload.rate.temp.kbps", 0, Integer.MAX_VALUE);
label = new Label(temp_rates, SWT.NULL);
Messages.setLanguageText(label, "label.duration.mins");
final IntParameter tempMins = new IntParameter(temp_rates, "global.rate.temp.min", 0, Integer.MAX_VALUE);
final Button activate = new Button(temp_rates, SWT.TOGGLE);
Messages.setLanguageText(activate, "label.activate");
final BufferedLabel remLabel = new BufferedLabel(temp_rates, SWT.DOUBLE_BUFFERED);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.widthHint = 150;
Utils.setLayoutData(remLabel, gridData);
activate.addSelectionListener(new SelectionAdapter() {
private CoreLifecycleAdapter listener;
private TimerEventPeriodic event;
private boolean auto_up_enabled;
private boolean auto_up_seeding_enabled;
private boolean seeding_limits_enabled;
private int up_limit;
private int down_limit;
private long end_time;
@Override
public void widgetSelected(SelectionEvent e) {
if (activate.getSelection()) {
listener = new CoreLifecycleAdapter() {
@Override
public void stopping(Core core) {
deactivate(true);
}
};
CoreFactory.getSingleton().addLifecycleListener(listener);
Messages.setLanguageText(activate, "FileView.BlockView.Active");
tempDLRate.setEnabled(false);
tempULRate.setEnabled(false);
tempMins.setEnabled(false);
auto_up_enabled = COConfigurationManager.getBooleanParameter(TransferSpeedValidator.AUTO_UPLOAD_ENABLED_CONFIGKEY);
auto_up_seeding_enabled = COConfigurationManager.getBooleanParameter(TransferSpeedValidator.AUTO_UPLOAD_SEEDING_ENABLED_CONFIGKEY);
seeding_limits_enabled = COConfigurationManager.getBooleanParameter(TransferSpeedValidator.UPLOAD_SEEDING_ENABLED_CONFIGKEY);
up_limit = COConfigurationManager.getIntParameter(TransferSpeedValidator.UPLOAD_CONFIGKEY);
down_limit = COConfigurationManager.getIntParameter(TransferSpeedValidator.DOWNLOAD_CONFIGKEY);
COConfigurationManager.setParameter(TransferSpeedValidator.AUTO_UPLOAD_ENABLED_CONFIGKEY, false);
COConfigurationManager.setParameter(TransferSpeedValidator.AUTO_UPLOAD_SEEDING_ENABLED_CONFIGKEY, false);
COConfigurationManager.setParameter(TransferSpeedValidator.UPLOAD_SEEDING_ENABLED_CONFIGKEY, false);
COConfigurationManager.setParameter(TransferSpeedValidator.UPLOAD_CONFIGKEY, tempULRate.getValue());
COConfigurationManager.setParameter(TransferSpeedValidator.DOWNLOAD_CONFIGKEY, tempDLRate.getValue());
end_time = SystemTime.getCurrentTime() + tempMins.getValue() * 60 * 1000;
event = SimpleTimer.addPeriodicEvent("TempRates", 1000, new TimerEventPerformer() {
@Override
public void perform(TimerEvent e) {
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
if (event == null) {
return;
}
long now = SystemTime.getCurrentTime();
long rem = end_time - now;
if (rem < 1000 || composite.isDisposed()) {
deactivate(false);
} else {
remLabel.setText(MessageText.getString("TableColumn.header.remaining") + ": " + DisplayFormatters.formatTime(rem));
}
}
});
}
});
} else {
deactivate(false);
}
}
private void deactivate(boolean closing) {
COConfigurationManager.setParameter(TransferSpeedValidator.AUTO_UPLOAD_ENABLED_CONFIGKEY, auto_up_enabled);
COConfigurationManager.setParameter(TransferSpeedValidator.AUTO_UPLOAD_SEEDING_ENABLED_CONFIGKEY, auto_up_seeding_enabled);
COConfigurationManager.setParameter(TransferSpeedValidator.UPLOAD_SEEDING_ENABLED_CONFIGKEY, seeding_limits_enabled);
COConfigurationManager.setParameter(TransferSpeedValidator.UPLOAD_CONFIGKEY, up_limit);
COConfigurationManager.setParameter(TransferSpeedValidator.DOWNLOAD_CONFIGKEY, down_limit);
if (!closing) {
if (listener != null) {
CoreFactory.getSingleton().removeLifecycleListener(listener);
listener = null;
}
if (!composite.isDisposed()) {
Messages.setLanguageText(activate, "label.activate");
activate.setSelection(false);
tempDLRate.setEnabled(true);
tempULRate.setEnabled(true);
tempMins.setEnabled(true);
remLabel.setText("");
}
}
if (event != null) {
event.cancel();
event = null;
}
}
});
activate.setEnabled(tempMins.getValue() > 0);
tempMins.addChangeListener(new ParameterChangeAdapter() {
@Override
public void parameterChanged(Parameter p, boolean caused_internally) {
activate.setEnabled(tempMins.getValue() > 0);
}
});
}
use of com.biglybt.core.CoreLifecycleAdapter in project BiglyBT by BiglySoftware.
the class ViewQuickConfig method addTemporaryData.
private void addTemporaryData(Composite composite) {
Group temp_rates = new Group(composite, SWT.NULL);
Messages.setLanguageText(temp_rates, "label.temporary.data");
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 4;
Utils.setLayoutData(temp_rates, gridData);
GridLayout layout = new GridLayout(10, false);
layout.marginWidth = 0;
layout.marginHeight = 0;
temp_rates.setLayout(layout);
// label = new Label(temp_rates, SWT.NULL);
// Messages.setLanguageText( label, "label.temporary.rates" );
Label label = new Label(temp_rates, SWT.NULL);
gridData = new GridData();
gridData.horizontalIndent = 4;
Utils.setLayoutData(label, gridData);
Messages.setLanguageText(label, "label.upload.mb", new String[] { DisplayFormatters.getUnit(DisplayFormatters.UNIT_MB) });
final IntParameter tempULLimit = new IntParameter(temp_rates, "global.upload.limit.temp.mb", 0, Integer.MAX_VALUE);
label = new Label(temp_rates, SWT.NULL);
Messages.setLanguageText(label, "label.download.mb", new String[] { DisplayFormatters.getUnit(DisplayFormatters.UNIT_MB) });
final IntParameter tempDLLimit = new IntParameter(temp_rates, "global.download.limit.temp.mb", 0, Integer.MAX_VALUE);
final Button activate = new Button(temp_rates, SWT.TOGGLE);
Messages.setLanguageText(activate, "label.activate");
final BufferedLabel remLabel = new BufferedLabel(temp_rates, SWT.DOUBLE_BUFFERED);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.widthHint = 200;
Utils.setLayoutData(remLabel, gridData);
activate.addSelectionListener(new SelectionAdapter() {
private CoreLifecycleAdapter listener;
private TimerEventPeriodic event;
private long end_upload;
private long end_download;
@Override
public void widgetSelected(SelectionEvent e) {
if (activate.getSelection()) {
listener = new CoreLifecycleAdapter() {
@Override
public void stopping(Core core) {
deactivate(true);
}
};
Core core = CoreFactory.getSingleton();
core.addLifecycleListener(listener);
Messages.setLanguageText(activate, "FileView.BlockView.Active");
final GlobalManagerStats stats = core.getGlobalManager().getStats();
tempULLimit.setEnabled(false);
tempDLLimit.setEnabled(false);
long u_limit = tempULLimit.getValue();
if (u_limit > 0) {
end_upload = stats.getTotalDataProtocolBytesSent() + u_limit * DisplayFormatters.getMinB();
} else {
end_upload = 0;
}
long d_limit = tempDLLimit.getValue();
if (d_limit > 0) {
end_download = stats.getTotalDataProtocolBytesReceived() + d_limit * DisplayFormatters.getMinB();
} else {
end_download = 0;
}
event = SimpleTimer.addPeriodicEvent("TempData", 5000, new TimerEventPerformer() {
@Override
public void perform(TimerEvent e) {
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
if (event == null) {
return;
}
long rem_up = 0;
long rem_down = 0;
if (end_upload > 0) {
rem_up = end_upload - stats.getTotalDataProtocolBytesSent();
}
if (end_download > 0) {
rem_down = end_download - stats.getTotalDataProtocolBytesReceived();
}
if (end_upload > 0 && rem_up <= 0) {
java.util.List<DownloadManager> dms = core.getGlobalManager().getDownloadManagers();
for (DownloadManager dm : dms) {
if (!dm.isForceStart()) {
int state = dm.getState();
if (state != DownloadManager.STATE_STOPPED && state != DownloadManager.STATE_ERROR && !dm.isPaused()) {
ManagerUtils.stop(dm, null);
dm.setStopReason(MessageText.getString("label.temporary.data"));
}
}
}
}
if (end_download > 0 && rem_down <= 0) {
java.util.List<DownloadManager> dms = core.getGlobalManager().getDownloadManagers();
for (DownloadManager dm : dms) {
if (!dm.isForceStart()) {
int state = dm.getState();
if (state != DownloadManager.STATE_STOPPED && state != DownloadManager.STATE_ERROR && !dm.isPaused()) {
if (!dm.isDownloadComplete(false)) {
ManagerUtils.stop(dm, null);
dm.setStopReason(MessageText.getString("label.temporary.data"));
}
}
}
}
}
if ((rem_up <= 0 && rem_down <= 0) || composite.isDisposed()) {
deactivate(false);
} else {
remLabel.setText(MessageText.getString("TableColumn.header.remaining") + ": " + DisplayFormatters.formatByteCountToKiBEtc(rem_up < 0 ? 0 : rem_up) + "/" + DisplayFormatters.formatByteCountToKiBEtc(rem_down < 0 ? 0 : rem_down));
temp_rates.layout(new Control[] { remLabel.getControl() });
}
}
});
}
});
} else {
deactivate(false);
}
}
private void deactivate(boolean closing) {
if (!closing) {
if (listener != null) {
CoreFactory.getSingleton().removeLifecycleListener(listener);
listener = null;
}
if (!composite.isDisposed()) {
Messages.setLanguageText(activate, "label.activate");
activate.setSelection(false);
tempULLimit.setEnabled(true);
tempDLLimit.setEnabled(true);
remLabel.setText("");
temp_rates.layout(true);
}
}
if (event != null) {
event.cancel();
event = null;
}
}
});
activate.setEnabled(tempULLimit.getValue() > 0 || tempDLLimit.getValue() > 0);
ParameterChangeAdapter adapter = new ParameterChangeAdapter() {
@Override
public void parameterChanged(Parameter p, boolean caused_internally) {
activate.setEnabled(tempULLimit.getValue() > 0 || tempDLLimit.getValue() > 0);
}
};
tempULLimit.addChangeListener(adapter);
tempDLLimit.addChangeListener(adapter);
}
use of com.biglybt.core.CoreLifecycleAdapter in project BiglyBT by BiglySoftware.
the class ActivitiesManager method _initialize.
static void _initialize(Core core) {
if (diag_logger != null) {
diag_logger.log("Initialize Called");
}
core.addLifecycleListener(new CoreLifecycleAdapter() {
@Override
public void stopping(Core core) {
if (saveEventsOnClose) {
saveEventsNow();
}
}
});
loadEvents();
replyListener = new PlatformVuzeActivitiesMessenger.GetEntriesReplyListener() {
@Override
public void gotVuzeNewsEntries(ActivitiesEntry[] entries, long refreshInMS) {
if (diag_logger != null) {
diag_logger.log("Received Reply from platform with " + entries.length + " entries. Refresh in " + refreshInMS);
}
addEntries(entries);
if (refreshInMS <= 0) {
refreshInMS = DEFAULT_PLATFORM_REFRESH;
}
SimpleTimer.addEvent("GetVuzeNews", SystemTime.getOffsetTime(refreshInMS), new TimerEventPerformer() {
@Override
public void perform(TimerEvent event) {
pullActivitiesNow(5000, "timer", false);
}
});
}
};
pullActivitiesNow(5000, "initial", false);
}
use of com.biglybt.core.CoreLifecycleAdapter in project BiglyBT by BiglySoftware.
the class Main method main.
public static void main(String[] args) {
if (DEBUG_STARTUPTIME) {
lastDebugTime = System.currentTimeMillis();
}
if (Launcher.checkAndLaunch(Main.class, args))
return;
// This *has* to be done first as it sets system properties that are read and cached by Java
COConfigurationManager.preInitialise();
if (DEBUG_STARTUPTIME) {
logTime("args: " + Arrays.toString(args));
}
Thread.currentThread().setName(Constants.APP_NAME);
String mi_str = System.getProperty("MULTI_INSTANCE");
boolean mi = mi_str != null && mi_str.equalsIgnoreCase("true");
if (DEBUG_STARTUPTIME) {
logTime("preInit");
}
try {
// Build a list of UIS
Options uiOptions = new Options();
Builder builder = Option.builder("u").longOpt("ui").argName("uis").hasArg();
uiOptions.addOption(builder.build());
if (Constants.isWindows) {
builder = Option.builder("console");
uiOptions.addOption(builder.build());
}
try {
CommandLine commandLine = new DefaultParser().parse(uiOptions, args, true);
buildUIList(commandLine);
} catch (ParseException e) {
}
// Add UIS Command Line Options
Options options = UIConst.buildOptions();
commands = UIConst.buildCommandLine(options, args);
if (commands == null) {
System.exit(0);
}
if (DEBUG_STARTUPTIME) {
logTime("buildCommandLine");
}
if (!mi) {
startServer = new StartServer();
if (startServer.getServerState() == StartServer.STATE_FAULTY) {
System.setProperty("transitory.startup", "1");
// looks like there's already a process listening on 127.0.0.1:<port>
// attempt to pass args to existing instance
// First, do some OSX magic because parameters are passed via OpenDocument API and other callbacks
args = CocoaMagic(args);
if (!new CoreSingleInstanceClient().sendArgs(args, 5000)) {
// arg passing attempt failed, so start core anyway
String msg = "There appears to be another process already listening on socket [127.0.0.1:" + Constants.INSTANCE_PORT + "].\n\nLocate and terminate the other program or change the control port - <a href=\"" + Constants.URL_WIKI + "w/Commandline_options#Changing_the_Control_Port\">see the wiki for details</a>.";
System.err.println(msg);
return;
} else {
// we sent params to other core, don't init the core
return;
}
}
if (commands.hasOption("closedown") || commands.hasOption("shutdown") || commands.hasOption("restart")) {
return;
}
if (DEBUG_STARTUPTIME) {
logTime("StartServer");
}
} else {
System.out.println("MULTI_INSTANCE enabled");
}
// Special Exit if user ask for help
if (commands != null && commands.hasOption('h')) {
HelpFormatter hf = new HelpFormatter();
hf.setOptionComparator(null);
hf.printHelp("[options] [torrent [torrent ...]]", options);
if (startServer != null) {
startServer.stopIt();
}
System.exit(0);
}
boolean isFirst = true;
for (IUserInterface ui : UIConst.UIS.values()) {
ui.init(isFirst, (UIConst.UIS.size() > 1));
isFirst = false;
}
neverStarted = true;
core = CoreFactory.create();
if (DEBUG_STARTUPTIME) {
logTime("Core Create");
}
for (IUserInterface ui : UIConst.UIS.values()) {
ui.coreCreated(core);
}
if (DEBUG_STARTUPTIME) {
logTime("UIConst.set" + Constants.AZUREUS_NAME + "Core");
}
UIConst.processArgs(commands, options, args);
if (DEBUG_STARTUPTIME) {
logTime("UIConst.processArgs");
}
if (startServer != null) {
startServer.setDaemon(true);
startServer.start();
}
neverStarted = !core.isStarted();
core.addLifecycleListener(new CoreLifecycleAdapter() {
@Override
public void started(Core core) {
Main.neverStarted = false;
}
@Override
public void stopping(Core core) {
Main.stopping = true;
}
@Override
public void stopped(Core core) {
if (startServer != null) {
startServer.stopIt();
}
Main.stopped = true;
}
});
for (IUserInterface ui : UIConst.UIS.values()) {
ui.takeMainThread();
if (stopping) {
break;
}
}
if (neverStarted) {
if (DEBUG_STARTUPTIME) {
logTime("takeMainThread");
}
core.start();
if (DEBUG_STARTUPTIME) {
logTime("coreStart");
}
}
if (!stopping) {
// no one took the main thread!
while (!stopped) {
try {
Thread.sleep(200);
// (not case "-u console,Swt")
if (newUI != null) {
IUserInterface threadTaker = newUI;
newUI = null;
threadTaker.takeMainThread();
}
} catch (InterruptedException e) {
}
}
}
} catch (CoreException e) {
System.out.println("Start fails:");
e.printStackTrace();
}
if (DEBUG_STARTUPTIME) {
logTime("DONE");
}
}
use of com.biglybt.core.CoreLifecycleAdapter in project BiglyBT by BiglySoftware.
the class UI method coreCreated.
@Override
public void coreCreated(Core core) {
super.coreCreated(core);
SimpleDateFormat temp = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
UIConst.startTime = new Date();
Logger.getLogger("biglybt").fatal(Constants.APP_NAME + " started at " + temp.format(UIConst.startTime));
core.addLifecycleListener(new CoreLifecycleAdapter() {
@Override
public void started(Core core) {
startUI();
}
@Override
public void stopped(Core core) {
super.stopped(core);
SimpleDateFormat temp = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
Logger.getLogger("biglybt").fatal(Constants.APP_NAME + " stopped at " + temp.format(new Date()));
}
});
if (core.isStarted()) {
startUI();
}
}
Aggregations