Source Code Cross Referenced for Scope.java in  » Rule-Engine » zilonis » org » zilonis » scope » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Rule Engine » zilonis » org.zilonis.scope 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.zilonis.scope;
002:
003:        /**
004:         * Copyright (c) 2005 Elie Levy <elie.levy@zilonis.org>
005:         * All rights reserved
006:         * 
007:         * This License governs use of the accompanying Software, and your use of the
008:         * Software constitutes acceptance of this license.
009:         * 
010:         * You may use this Software for any non-commercial purpose, subject to the
011:         * restrictions in this license. Some purposes which can be non-commercial are
012:         * teaching, academic research, and personal experimentation. You may also
013:         * distribute this Software with books or other teaching materials, or publish
014:         * the Software on websites, that are intended to teach the use of the 
015:         * Software.
016:         * 
017:         * 
018:         * You may not use or distribute this Software or any derivative works in any
019:         * form for commercial purposes. Examples of commercial purposes would be
020:         * running business operations, licensing, leasing, or selling the Software, or
021:         * distributing the Software for use with commercial products.
022:         * 
023:         * You may modify this Software and distribute the modified Software for
024:         * non-commercial purposes, however, you may not grant rights to the Software 
025:         * or derivative works that are broader than those provided by this License. 
026:         * For example, you may not distribute modifications of the Software under
027:         * terms that would permit commercial use, or under terms that purport to 
028:         * require the Software or derivative works to be sublicensed to others.
029:         * 
030:         * You may use any information in intangible form that you remember after
031:         * accessing the Software. However, this right does not grant you a license to
032:         * any of the copyrights or patents for anything you might create using such
033:         * information.
034:         * 
035:         * In return, we simply require that you agree:
036:         * 
037:         * Not to remove any copyright or other notices from the Software.
038:         * 
039:         * 
040:         * That if you distribute the Software in source or object form, you will
041:         * include a verbatim copy of this license.
042:         * 
043:         * 
044:         * That if you distribute derivative works of the Software in source code form
045:         * you do so only under a license that includes all of the provisions of this
046:         * License, and if you distribute derivative works of the Software solely in
047:         * object form you do so only under a license that complies with this License.
048:         * 
049:         * 
050:         * That if you have modified the Software or created derivative works, and
051:         * distribute such modifications or derivative works, you will cause the
052:         * modified files to carry prominent notices so that recipients know that they
053:         * are not receiving the original Software. Such notices must state: (i) that
054:         * you have changed the Software; and (ii) the date of any changes.
055:         * 
056:         * 
057:         * THAT THE SOFTWARE COMES "AS IS", WITH NO WARRANTIES. THIS MEANS NO EXPRESS,
058:         * IMPLIED OR STATUTORY WARRANTY, INCLUDING WITHOUT LIMITATION, WARRANTIES OF
059:         * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE OR ANY WARRANTY OF TITLE
060:         * OR NON-INFRINGEMENT. ALSO, YOU MUST PASS THIS DISCLAIMER ON WHENEVER YOU
061:         * DISTRIBUTE THE SOFTWARE OR DERIVATIVE WORKS.
062:         * 
063:         * 
064:         * THAT NEITHER ZILONIS NOR THE AUTHOR WILL BE LIABLE FOR ANY DAMAGES RELATED
065:         * TO THE SOFTWARE OR THIS LICENSE, INCLUDING DIRECT, INDIRECT, SPECIAL,
066:         * CONSEQUENTIAL OR INCIDENTAL DAMAGES, TO THE MAXIMUM EXTENT THE LAW PERMITS,
067:         * NO MATTER WHAT LEGAL THEORY IT IS BASED ON. ALSO, YOU MUST PASS THIS
068:         * LIMITATION OF LIABILITY ON WHENEVER YOU DISTRIBUTE THE SOFTWARE OR 
069:         * DERIVATIVE WORKS.
070:         * 
071:         * 
072:         * That if you sue anyone over patents that you think may apply to the Software
073:         * or anyone's use of the Software, your license to the Software ends
074:         * automatically.
075:         * 
076:         * 
077:         * That your rights under the License end automatically if you breach it in any
078:         * way.
079:         * 
080:         * 
081:         * Elie Levy reserves all rights not expressly granted to you in this 
082:         * license.
083:         *  
084:         */
085:
086:        import java.util.LinkedList;
087:        import java.util.concurrent.locks.ReentrantReadWriteLock;
088:        import java.util.Iterator;
089:        import org.zilonis.util.MultiList;
090:        import org.zilonis.network.WME;
091:
092:        public class Scope {
093:
094:            private ReentrantReadWriteLock lock;
095:
096:            private Scope parent;
097:
098:            private LinkedList<Scope> children;
099:
100:            private int level;
101:
102:            private long lastId;
103:
104:            private MultiList wmeInScope;
105:
106:            public final static Scope ROOT = new Scope();
107:
108:            private Scope(Scope parent) {
109:                this ();
110:                this .parent = parent;
111:                level = parent.getLevel() + 1;
112:                getReadLock();
113:                parent.addChild(this );
114:                releaseReadLock();
115:            }
116:
117:            private Scope() {
118:                children = new LinkedList<Scope>();
119:                lock = new ReentrantReadWriteLock();
120:                wmeInScope = new MultiList(WME.SCOPE);
121:            }
122:
123:            public Iterator<WME> getWMEIterator() {
124:                return wmeInScope.iterator();
125:            }
126:
127:            public void addWME(WME wme) {
128:                wmeInScope.add(wme);
129:            }
130:
131:            public void terminate() {
132:                wmeInScope.removeAll();
133:            }
134:
135:            public Scope getParent() {
136:                return parent;
137:            }
138:
139:            public synchronized long getNextId() {
140:                return lastId++;
141:            }
142:
143:            public LinkedList<Scope> getChildren() {
144:                return children;
145:            }
146:
147:            public int getLevel() {
148:                return level;
149:            }
150:
151:            public int compareTo(Scope scope) {
152:                return level - scope.getLevel();
153:            }
154:
155:            public Scope createChild() {
156:                return new Scope(this );
157:            }
158:
159:            private void addChild(Scope child) {
160:                children.add(child);
161:            }
162:
163:            public void lock() {
164:                if (parent != null)
165:                    parent.getReadLock();
166:                getWriteLock();
167:            }
168:
169:            public void unlock() {
170:                if (parent != null)
171:                    parent.releaseReadLock();
172:                releaseWriteLocks();
173:            }
174:
175:            private void releaseReadLock() {
176:                if (parent != null)
177:                    parent.releaseReadLock();
178:                lock.readLock().unlock();
179:            }
180:
181:            private void releaseWriteLocks() {
182:                lock.writeLock().unlock();
183:                for (Scope child : children)
184:                    child.releaseWriteLocks();
185:            }
186:
187:            private void getReadLock() {
188:                if (parent != null)
189:                    parent.getReadLock();
190:                lock.readLock().lock();
191:            }
192:
193:            private void getWriteLock() {
194:                lock.writeLock().lock();
195:                for (Scope child : children)
196:                    child.getWriteLock();
197:            }
198:
199:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.