KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > viewers > AsynchronousSchedulingRuleFactory


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.viewers;
12
13 import org.eclipse.core.runtime.jobs.ISchedulingRule;
14
15 /**
16  * Scheduling rule factory for asycn operations.
17  *
18  * @since 3.2
19  */

20 public class AsynchronousSchedulingRuleFactory {
21     
22     private static AsynchronousSchedulingRuleFactory fgFactory = null;
23
24     /**
25      * Rule allows only one job to run at a time
26      */

27     class SerialRule implements ISchedulingRule {
28
29         public SerialRule() {
30         }
31
32         public boolean contains(ISchedulingRule rule) {
33             return rule == this;
34         }
35
36         public boolean isConflicting(ISchedulingRule rule) {
37             return rule instanceof SerialRule;
38         }
39     }
40     
41    class SerialPerObjectRule implements ISchedulingRule {
42         
43         private Object JavaDoc fObject = null;
44         
45         public SerialPerObjectRule(Object JavaDoc lock) {
46             fObject = lock;
47         }
48
49         /* (non-Javadoc)
50          * @see org.eclipse.core.runtime.jobs.ISchedulingRule#contains(org.eclipse.core.runtime.jobs.ISchedulingRule)
51          */

52         public boolean contains(ISchedulingRule rule) {
53             return rule == this;
54         }
55
56         /* (non-Javadoc)
57          * @see org.eclipse.core.runtime.jobs.ISchedulingRule#isConflicting(org.eclipse.core.runtime.jobs.ISchedulingRule)
58          */

59         public boolean isConflicting(ISchedulingRule rule) {
60             if (rule instanceof SerialPerObjectRule) {
61                 SerialPerObjectRule vup = (SerialPerObjectRule) rule;
62                 return fObject == vup.fObject;
63             }
64             return false;
65         }
66         
67     }
68     
69     private AsynchronousSchedulingRuleFactory() {}
70     
71     public static AsynchronousSchedulingRuleFactory getDefault() {
72         if (fgFactory == null) {
73             fgFactory = new AsynchronousSchedulingRuleFactory();
74         }
75         return fgFactory;
76     }
77     
78     /**
79      * Returns a scheulding rule that allows all jobs with an instance
80      * of the rule to run one at a time.
81      *
82      * @return scheduling rule
83      */

84     public ISchedulingRule newSerialRule() {
85         return new SerialRule();
86     }
87     
88     /**
89      * Returns a scheduling rule that allows all jobs with an instance
90      * of the rule on the same object to run one at a time.
91      *
92      * @param lock object to serialize one
93      * @return scheduling rule
94      */

95     public ISchedulingRule newSerialPerObjectRule(Object JavaDoc lock) {
96         return new SerialPerObjectRule(lock);
97     }
98     
99 }
100
Popular Tags