Source Code Cross Referenced for DefaultServer.java in  » UML » AndroMDA-3.2 » org » andromda » core » server » 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 » UML » AndroMDA 3.2 » org.andromda.core.server 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.andromda.core.server;
002:
003:        import java.io.DataInputStream;
004:        import java.io.IOException;
005:        import java.io.ObjectInputStream;
006:        import java.io.ObjectOutputStream;
007:
008:        import java.net.ServerSocket;
009:        import java.net.Socket;
010:        import java.net.SocketTimeoutException;
011:
012:        import org.andromda.core.common.AndroMDALogger;
013:        import org.andromda.core.configuration.Configuration;
014:        import org.andromda.core.engine.Engine;
015:
016:        /**
017:         * The default AndroMDA {@link Server instance}.
018:         *
019:         * @author Chad Brandon
020:         */
021:        public class DefaultServer implements  Server {
022:            /**
023:             * The message sent to the client when AndroMDA processing has completed.
024:             */
025:            private static final String COMPLETE = "complete";
026:
027:            /**
028:             * The command sent to the server that indicates it
029:             * should stop.
030:             */
031:            static final String STOP = "stop";
032:
033:            /**
034:             * The server listener.
035:             */
036:            private ServerSocket listener = null;
037:
038:            /**
039:             * The AndroMDA Engine instance.
040:             */
041:            private Engine engine = Engine.newInstance();
042:
043:            /**
044:             * @see org.andromda.core.server.Server#start(org.andromda.core.configuration.Configuration)
045:             */
046:            public void start(final Configuration configuration) {
047:                engine.initialize(configuration);
048:                if (configuration != null) {
049:                    final org.andromda.core.configuration.Server serverConfiguration = configuration
050:                            .getServer();
051:                    if (serverConfiguration != null) {
052:                        try {
053:                            try {
054:                                this .listener = new ServerSocket(
055:                                        serverConfiguration.getPort());
056:                                final int modelLoadInterval = serverConfiguration
057:                                        .getLoadInterval();
058:                                if (modelLoadInterval > 0) {
059:                                    this .listener
060:                                            .setSoTimeout(serverConfiguration
061:                                                    .getLoadInterval());
062:                                }
063:                            } catch (final IOException exception) {
064:                                throw new ServerException(
065:                                        "Could not listen on port '"
066:                                                + serverConfiguration.getPort()
067:                                                + "', change the port in your configuration");
068:                            }
069:                            while (true) {
070:                                try {
071:                                    final Socket client = this .listener
072:                                            .accept();
073:                                    if (client != null) {
074:                                        final ObjectOutputStream serverOutput = new ObjectOutputStream(
075:                                                client.getOutputStream());
076:                                        final ObjectInputStream objectInput = new ObjectInputStream(
077:                                                new DataInputStream(client
078:                                                        .getInputStream()));
079:                                        try {
080:                                            final Object object = objectInput
081:                                                    .readObject();
082:                                            if (object instanceof  Configuration) {
083:                                                this .engine
084:                                                        .run((Configuration) object);
085:                                            } else if (object instanceof  String) {
086:                                                final String string = (String) object;
087:                                                if (string.equals(STOP)) {
088:                                                    break;
089:                                                }
090:                                            }
091:                                        } catch (final Throwable throwable) {
092:                                            AndroMDALogger.error(throwable);
093:
094:                                            // - pass the exception to the client
095:                                            serverOutput.writeObject(throwable);
096:                                        }
097:
098:                                        // - signal to the client, it can stop waiting
099:                                        serverOutput.writeObject(COMPLETE);
100:                                        serverOutput.flush();
101:                                        serverOutput.close();
102:                                        objectInput.close();
103:                                        client.close();
104:                                    }
105:                                } catch (final SocketTimeoutException exception) {
106:                                    try {
107:                                        this .engine
108:                                                .loadModelsIfNecessary(configuration);
109:                                        this .resetFailedLoadAttempts();
110:                                    } catch (final Throwable throwable) {
111:                                        this .incrementFailedLoadAttempts();
112:
113:                                        // - only fail if the failed load attempts is greater than the maximum
114:                                        if (this .failedLoadAttempts > serverConfiguration
115:                                                .getMaximumFailedLoadAttempts()) {
116:                                            throw throwable;
117:                                        }
118:                                    }
119:                                }
120:                            }
121:                            this .shutdown();
122:                        } catch (final Throwable throwable) {
123:                            throw new ServerException(throwable);
124:                        }
125:                    }
126:                }
127:            }
128:
129:            /**
130:             * Stores the failed load attempts.
131:             */
132:            private int failedLoadAttempts;
133:
134:            /**
135:             * Resets the failed load attempt counter.
136:             */
137:            private void resetFailedLoadAttempts() {
138:                this .failedLoadAttempts = 0;
139:            }
140:
141:            /**
142:             * Increments the failed load attempt counter.
143:             */
144:            private void incrementFailedLoadAttempts() {
145:                this .failedLoadAttempts++;
146:            }
147:
148:            /**
149:             * Shuts the server down.
150:             */
151:            public void shutdown() {
152:                try {
153:                    this .listener.close();
154:                    this .listener = null;
155:                    this .engine.shutdown();
156:                } catch (final IOException exception) {
157:                    // ignore exception
158:                }
159:            }
160:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.