summaryrefslogtreecommitdiff
path: root/java/demo/Database/library/RunParser.java
diff options
context:
space:
mode:
authorMatthew Newhook <matthew@zeroc.com>2015-03-18 12:58:16 -0230
committerMatthew Newhook <matthew@zeroc.com>2015-03-18 12:58:16 -0230
commit9b7668c7c92cf9cb311fe444cdddb489cd2a219d (patch)
tree5016567c58c81f5654e9d01935e199c6bf4761d2 /java/demo/Database/library/RunParser.java
parentVS add-in & build updates: (diff)
downloadice-9b7668c7c92cf9cb311fe444cdddb489cd2a219d.tar.bz2
ice-9b7668c7c92cf9cb311fe444cdddb489cd2a219d.tar.xz
ice-9b7668c7c92cf9cb311fe444cdddb489cd2a219d.zip
Removed demos.
Moved demoscript to distribution.
Diffstat (limited to 'java/demo/Database/library/RunParser.java')
-rw-r--r--java/demo/Database/library/RunParser.java203
1 files changed, 0 insertions, 203 deletions
diff --git a/java/demo/Database/library/RunParser.java b/java/demo/Database/library/RunParser.java
deleted file mode 100644
index 978446389d1..00000000000
--- a/java/demo/Database/library/RunParser.java
+++ /dev/null
@@ -1,203 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-
-import Demo.*;
-
-class RunParser
-{
- //
- // Adapter for the two types of session objects.
- //
- interface SessionAdapter
- {
- public LibraryPrx getLibrary();
- public void destroy();
- public void refresh();
- public long getTimeout();
- }
-
- static SessionAdapter
- createSession(String appName, Ice.Communicator communicator) {
- SessionAdapter session;
- final Glacier2.RouterPrx router = Glacier2.RouterPrxHelper.uncheckedCast(communicator.getDefaultRouter());
- if(router != null)
- {
- Glacier2.SessionPrx glacier2session = null;
- long timeout;
- java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
- while(true)
- {
- System.out.println("This demo accepts any user-id / password combination.");
- try
- {
- String id;
- System.out.print("user id: ");
- System.out.flush();
- id = in.readLine();
-
- String pw;
- System.out.print("password: ");
- System.out.flush();
- pw = in.readLine();
-
- try
- {
- glacier2session = router.createSession(id, pw);
- timeout = router.getSessionTimeout() / 2;
- break;
- }
- catch(Glacier2.PermissionDeniedException ex)
- {
- System.out.println("permission denied:\n" + ex.reason);
- }
- catch(Glacier2.CannotCreateSessionException ex)
- {
- System.out.println("cannot create session:\n" + ex.reason);
- }
- }
- catch(java.io.IOException ex)
- {
- ex.printStackTrace();
- }
- }
- final long to = timeout;
- final Glacier2SessionPrx sess = Glacier2SessionPrxHelper.uncheckedCast(glacier2session);
- session = new SessionAdapter()
- {
- @Override
- public LibraryPrx getLibrary()
- {
- return sess.getLibrary();
- }
-
- @Override
- public void destroy()
- {
- try
- {
- router.destroySession();
- }
- catch(Glacier2.SessionNotExistException ex)
- {
- }
- catch(Ice.ConnectionLostException ex)
- {
- //
- // Expected: the router closed the connection.
- //
- }
- }
-
- @Override
- public void refresh()
- {
- sess.refresh();
- }
-
- @Override
- public long getTimeout()
- {
- return to;
- }
- };
- }
- else
- {
- SessionFactoryPrx factory = SessionFactoryPrxHelper.checkedCast(
- communicator.propertyToProxy("SessionFactory.Proxy"));
- if(factory == null)
- {
- System.err.println(appName + ": invalid object reference");
- return null;
- }
-
- final SessionPrx sess = factory.create();
- final long timeout = factory.getSessionTimeout()/2;
- session = new SessionAdapter()
- {
- @Override
- public LibraryPrx getLibrary()
- {
- return sess.getLibrary();
- }
-
- @Override
- public void destroy()
- {
- sess.destroy();
- }
-
- @Override
- public void refresh()
- {
- sess.refresh();
- }
-
- @Override
- public long getTimeout()
- {
- return timeout;
- }
- };
- }
- return session;
- }
-
- static int
- runParser(String appName, String[] args, final Ice.Communicator communicator)
- {
- final SessionAdapter session = createSession(appName, communicator);
- if(session == null)
- {
- return 1;
- }
-
- java.util.concurrent.ScheduledExecutorService executor = java.util.concurrent.Executors.newScheduledThreadPool(1);
- executor.scheduleAtFixedRate(new Runnable()
- {
- @Override
- public void
- run()
- {
- try
- {
- session.refresh();
- }
- catch(Ice.LocalException ex)
- {
- communicator.getLogger().warning("SessionRefreshThread: " + ex);
- // Exceptions thrown from the executor task supress subsequent execution
- // of the task.
- throw ex;
- }
- }
- }, session.getTimeout(), session.getTimeout(), java.util.concurrent.TimeUnit.SECONDS);
-
- LibraryPrx library = session.getLibrary();
-
- Parser parser = new Parser(communicator, library);
-
- int rc = 0;
-
- if(args.length == 1)
- {
- rc = parser.parse(args[0]);
- }
-
- if(rc == 0)
- {
- rc = parser.parse();
- }
-
- executor.shutdown();
- session.destroy();
-
- return rc;
- }
-}