Download | Plain Text | No Line Numbers


  1. /*
  2.  * Copyright (c) 2010, Manuel Mausz. All rights reserved.
  3.  *
  4.  * Redistribution and use in source and binary forms, with or without
  5.  * modification, are permitted provided that the following conditions
  6.  * are met:
  7.  *
  8.  * - Redistributions of source code must retain the above copyright
  9.  * notice, this list of conditions and the following disclaimer.
  10.  *
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  * notice, this list of conditions and the following disclaimer in the
  13.  * documentation and/or other materials provided with the distribution.
  14.  *
  15.  * - The names of the authors may not be used to endorse or promote products
  16.  * derived from this software without specific prior written permission.
  17.  *
  18.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19.  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  20.  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  21.  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  22.  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23.  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24.  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  25.  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  26.  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27.  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28.  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29.  */
  30.  
  31. import java.rmi.server.UnicastRemoteObject;
  32. import java.rmi.NoSuchObjectException;
  33. import java.rmi.RemoteException;
  34. import java.rmi.Remote;
  35. import java.util.ArrayList;
  36.  
  37. /*
  38.  * remote interface implementation
  39.  *
  40.  * @author Manuel Mausz (0728348)
  41.  */
  42. public class RemoteInterfaceImpl
  43. extends UnicastRemoteObject
  44. implements RemoteInterface
  45. {
  46. private Server server;
  47. private ArrayList<Remote> exported;
  48.  
  49. RemoteInterfaceImpl(Server server)
  50. throws RemoteException
  51. {
  52. this.server = server;
  53. exported = new ArrayList<Remote>();
  54. }
  55.  
  56. public S2SInterface s2sInterfaceFactory()
  57. throws RemoteException
  58. {
  59. S2SInterface tmp = new S2SInterfaceImpl(server);
  60. exported.add(tmp);
  61. return tmp;
  62. }
  63.  
  64. public C2SInterface c2sInterfaceFactory()
  65. throws RemoteException
  66. {
  67. if (!server.ready)
  68. return null;
  69. C2SInterface tmp = new C2SInterfaceImpl(server);
  70. exported.add(tmp);
  71. return tmp;
  72. }
  73.  
  74. public void unexport(Remote obj)
  75. throws RemoteException
  76. {
  77. try
  78. {
  79. UnicastRemoteObject.unexportObject(obj, true);
  80. }
  81. catch(NoSuchObjectException e)
  82. {}
  83. }
  84.  
  85. public void unexportAll()
  86. throws RemoteException
  87. {
  88. exported.add(this);
  89. for(Remote obj : exported)
  90. unexport(obj);
  91. }
  92. }
  93.