Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 298416
Collapse All | Expand All

(-)defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/BaseStorage.java (-8 / +44 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2009 IBM Corporation and others.
2
 * Copyright (c) 2005, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 421-426 Link Here
421
	}
421
	}
422
422
423
	private void saveAllData(boolean shutdown) {
423
	private void saveAllData(boolean shutdown) {
424
		if (Debug.DEBUG && Debug.DEBUG_GENERAL)
425
			Debug.println("Saving framework data ..."); //$NON-NLS-1$
424
		if (storageManagerClosed)
426
		if (storageManagerClosed)
425
			try {
427
			try {
426
				storageManager.open(!LocationManager.getConfigurationLocation().isReadOnly());
428
				storageManager.open(!LocationManager.getConfigurationLocation().isReadOnly());
Lines 485-490 Link Here
485
	private void savePermissionStorage() {
487
	private void savePermissionStorage() {
486
		if (permissionStorage == null || isReadOnly() || !permissionStorage.isDirty())
488
		if (permissionStorage == null || isReadOnly() || !permissionStorage.isDirty())
487
			return;
489
			return;
490
		if (Debug.DEBUG && Debug.DEBUG_GENERAL)
491
			Debug.println("About to save permission data ..."); //$NON-NLS-1$
488
		try {
492
		try {
489
			ManagedOutputStream fmos = storageManager.getOutputStream(PERM_DATA_FILE);
493
			ManagedOutputStream fmos = storageManager.getOutputStream(PERM_DATA_FILE);
490
			DataOutputStream out = new DataOutputStream(new BufferedOutputStream(fmos));
494
			DataOutputStream out = new DataOutputStream(new BufferedOutputStream(fmos));
Lines 536-541 Link Here
536
		// the cache and the state match
540
		// the cache and the state match
537
		if (stateManager == null || isReadOnly() || (timeStamp == stateManager.getSystemState().getTimeStamp() && !stateManager.saveNeeded()))
541
		if (stateManager == null || isReadOnly() || (timeStamp == stateManager.getSystemState().getTimeStamp() && !stateManager.saveNeeded()))
538
			return;
542
			return;
543
		if (Debug.DEBUG && Debug.DEBUG_GENERAL)
544
			Debug.println("Saving bundle data ..."); //$NON-NLS-1$
539
		try {
545
		try {
540
			ManagedOutputStream fmos = storageManager.getOutputStream(LocationManager.BUNDLE_DATA_FILE);
546
			ManagedOutputStream fmos = storageManager.getOutputStream(LocationManager.BUNDLE_DATA_FILE);
541
			DataOutputStream out = new DataOutputStream(new BufferedOutputStream(fmos));
547
			DataOutputStream out = new DataOutputStream(new BufferedOutputStream(fmos));
Lines 589-594 Link Here
589
			stateManager.getSystemState().setTimeStamp(stateManager.getSystemState().getTimeStamp() + 1);
595
			stateManager.getSystemState().setTimeStamp(stateManager.getSystemState().getTimeStamp() + 1);
590
		if (stateManager == null || isReadOnly() || !stateManager.saveNeeded())
596
		if (stateManager == null || isReadOnly() || !stateManager.saveNeeded())
591
			return;
597
			return;
598
		if (Debug.DEBUG && Debug.DEBUG_GENERAL)
599
			Debug.println("Saving resolver state data ..."); //$NON-NLS-1$
592
		File stateTmpFile = null;
600
		File stateTmpFile = null;
593
		File lazyTmpFile = null;
601
		File lazyTmpFile = null;
594
		try {
602
		try {
Lines 1148-1172 Link Here
1148
	}
1156
	}
1149
1157
1150
	private class StateSaver implements Runnable {
1158
	private class StateSaver implements Runnable {
1151
		private long delay_interval = 30000; // 30 seconds.
1159
		private final long delay_interval;
1152
		private long max_total_delay_interval = 1800000; // 30 minutes.
1160
		private final long max_total_delay_interval;
1153
		private boolean shutdown = false;
1161
		private boolean shutdown = false;
1154
		private long lastSaveTime = 0;
1162
		private long lastSaveTime = 0;
1155
		private Thread runningThread = null;
1163
		private Thread runningThread = null;
1164
		private Thread shutdownHook = null;
1156
1165
1157
		StateSaver() {
1166
		StateSaver() {
1158
			String prop = FrameworkProperties.getProperty("eclipse.stateSaveDelayInterval"); //$NON-NLS-1$
1167
			String prop = FrameworkProperties.getProperty("eclipse.stateSaveDelayInterval"); //$NON-NLS-1$
1168
			long delayValue = 30000; // 30 seconds.
1169
			long maxDelayValue = 1800000; // 30 minutes.
1159
			if (prop != null) {
1170
			if (prop != null) {
1160
				try {
1171
				try {
1161
					long val = Long.parseLong(prop);
1172
					long val = Long.parseLong(prop);
1162
					if (val >= 1000 && val <= 1800000) {
1173
					if (val >= 1000 && val <= 1800000) {
1163
						delay_interval = val;
1174
						delayValue = val;
1164
						max_total_delay_interval = val * 60;
1175
						maxDelayValue = val * 60;
1176
					} else if (val == 0) {
1177
						delayValue = 0;
1178
						maxDelayValue = 0;
1165
					}
1179
					}
1166
				} catch (NumberFormatException e) {
1180
				} catch (NumberFormatException e) {
1167
					// ignore
1181
					// ignore
1168
				}
1182
				}
1169
			}
1183
			}
1184
			delay_interval = delayValue;
1185
			max_total_delay_interval = maxDelayValue;
1170
		}
1186
		}
1171
1187
1172
		public void run() {
1188
		public void run() {
Lines 1200-1205 Link Here
1200
					// Continue the loop if Saver is asked again during saving State data to file.
1216
					// Continue the loop if Saver is asked again during saving State data to file.
1201
				} while (!shutdown && curSaveTime < lastSaveTime);
1217
				} while (!shutdown && curSaveTime < lastSaveTime);
1202
				runningThread = null; // clear runningThread
1218
				runningThread = null; // clear runningThread
1219
				try {
1220
					Runtime.getRuntime().removeShutdownHook(shutdownHook);
1221
				} catch (IllegalStateException e) {
1222
					// avoid exception if shutdown is in progress
1223
				}
1224
				shutdownHook = null;
1203
			}
1225
			}
1204
		}
1226
		}
1205
1227
Lines 1213-1220 Link Here
1213
			}
1235
			}
1214
			try {
1236
			try {
1215
				if (joinWith != null)
1237
				if (joinWith != null)
1216
					// There should be no deadlock when 'shutdown' is true.
1238
					if (Debug.DEBUG && Debug.DEBUG_GENERAL)
1217
					joinWith.join();
1239
						Debug.println("About to join saving thread"); //$NON-NLS-1$
1240
				// There should be no deadlock when 'shutdown' is true.
1241
				joinWith.join();
1242
				if (Debug.DEBUG && Debug.DEBUG_GENERAL)
1243
					Debug.println("Joined with saving thread"); //$NON-NLS-1$
1218
			} catch (InterruptedException ie) {
1244
			} catch (InterruptedException ie) {
1219
				if (Debug.DEBUG && Debug.DEBUG_GENERAL) {
1245
				if (Debug.DEBUG && Debug.DEBUG_GENERAL) {
1220
					Debug.println("Error shutdowning StateSaver: " + ie.getMessage()); //$NON-NLS-1$
1246
					Debug.println("Error shutdowning StateSaver: " + ie.getMessage()); //$NON-NLS-1$
Lines 1224-1235 Link Here
1224
		}
1250
		}
1225
1251
1226
		void requestSave() {
1252
		void requestSave() {
1227
			State systemState = adaptor.getState();
1253
			final State systemState = adaptor.getState();
1228
			synchronized (systemState) {
1254
			synchronized (systemState) {
1229
				if (shutdown)
1255
				if (shutdown)
1230
					return; // do not start another thread if we have already shutdown
1256
					return; // do not start another thread if we have already shutdown
1257
				if (delay_interval == 0) // all saves are atomic
1258
					saveAllData(false);
1231
				lastSaveTime = System.currentTimeMillis();
1259
				lastSaveTime = System.currentTimeMillis();
1232
				if (runningThread == null) {
1260
				if (runningThread == null) {
1261
					shutdownHook = new Thread(new Runnable() {
1262
						public void run() {
1263
							synchronized (systemState) {
1264
								saveAllData(false);
1265
							}
1266
						}
1267
					});
1268
					Runtime.getRuntime().addShutdownHook(shutdownHook);
1233
					runningThread = new Thread(this, "State Saver"); //$NON-NLS-1$
1269
					runningThread = new Thread(this, "State Saver"); //$NON-NLS-1$
1234
					runningThread.start();
1270
					runningThread.start();
1235
				}
1271
				}

Return to bug 298416