Source Code Cross Referenced for T_Serviceable.java in  » Database-DBMS » db-derby-10.2 » org » apache » derbyTesting » unitTests » services » 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 » Database DBMS » db derby 10.2 » org.apache.derbyTesting.unitTests.services 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:           Derby - Class org.apache.derbyTesting.unitTests.services.T_Serviceable
004:
005:           Licensed to the Apache Software Foundation (ASF) under one or more
006:           contributor license agreements.  See the NOTICE file distributed with
007:           this work for additional information regarding copyright ownership.
008:           The ASF licenses this file to You under the Apache License, Version 2.0
009:           (the "License"); you may not use this file except in compliance with
010:           the License.  You may obtain a copy of the License at
011:
012:              http://www.apache.org/licenses/LICENSE-2.0
013:
014:           Unless required by applicable law or agreed to in writing, software
015:           distributed under the License is distributed on an "AS IS" BASIS,
016:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017:           See the License for the specific language governing permissions and
018:           limitations under the License.
019:
020:         */
021:
022:        package org.apache.derbyTesting.unitTests.services;
023:
024:        import org.apache.derbyTesting.unitTests.harness.T_Generic;
025:        import org.apache.derbyTesting.unitTests.harness.T_Fail;
026:
027:        import org.apache.derby.iapi.services.context.Context;
028:        import org.apache.derby.iapi.services.context.ContextManager;
029:        import org.apache.derby.iapi.services.monitor.Monitor;
030:        import org.apache.derby.iapi.error.StandardException;
031:        import org.apache.derby.iapi.services.daemon.*;
032:
033:        /**
034:         This test implements serviceable for testing.  To facility testing, when
035:         this object is being serviced, it will synchronize on itself and notity all
036:         waiters.  Test driver may wait on this object and check timesServiced to
037:         make sure the background daemon has run.
038:         */
039:        public class T_Serviceable implements  Serviceable {
040:            // synchronized on this to look at the number 
041:            // of times this object has been serviced
042:            protected int timesServiced;
043:
044:            // constant for checking
045:            protected final int timesRequeue;
046:            protected final boolean onDemandOnly;
047:            protected final boolean subscribed;
048:
049:            // use this to unsubscribe
050:            protected int clientNumber;
051:
052:            // test enqueueing, t = number of times to requeue
053:            public T_Serviceable(int t) {
054:                timesServiced = 0;
055:                timesRequeue = t;
056:                onDemandOnly = false; // not looked at
057:                subscribed = false;
058:                clientNumber = -1;
059:            }
060:
061:            // test subscription 
062:            public T_Serviceable(boolean onDemandOnly) {
063:                timesServiced = 0;
064:                timesRequeue = 0; // not looked at
065:                this .onDemandOnly = onDemandOnly;
066:                subscribed = true;
067:            }
068:
069:            protected void setClientNumber(int n) {
070:                clientNumber = n;
071:            }
072:
073:            protected int getClientNumber() {
074:                return clientNumber;
075:            }
076:
077:            /*
078:             *  Serviceable interface
079:             */
080:            public synchronized int performWork(ContextManager context) {
081:                context.toString(); // make sure context manager is not null;
082:
083:                timesServiced++;
084:                notifyAll(); // notify anyone waiting for me to be serviced
085:
086:                if (!subscribed && timesRequeue > timesServiced)
087:                    return Serviceable.REQUEUE;
088:                else
089:                    return Serviceable.DONE;
090:            }
091:
092:            public boolean serviceASAP() {
093:                return true;
094:            }
095:
096:            // @return true, if this work needs to be done on a user thread immediately
097:            public boolean serviceImmediately() {
098:                return false;
099:            }
100:
101:            /*
102:             * test utilities
103:             */
104:
105:            protected synchronized void t_wait(int n) {
106:                try {
107:                    while (timesServiced < n)
108:                        wait();
109:                } catch (InterruptedException ie) {
110:                }
111:            }
112:
113:            protected synchronized void t_check(int n) throws T_Fail {
114:                if (timesServiced != n)
115:                    throw T_Fail.testFailMsg("Expect to be serviced " + n
116:                            + " times, instead serviced " + timesServiced);
117:            }
118:
119:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.