|
Прохожу курс "Построение распределенных систем на Java" в третьей лекции где описывается TCPServer вылетает эта ошибка
"Connection cannot be resolved to a type" Java version 1.7.0_05 |
CORBA. Второй пример
Файл _BillingServiceStub.java (пример 8.6) содержит клиентскую заглушку. Класс BillingServiceStub наследует от org.omg.CORBA.portable. ObjectImpl и реализует интерфейс BillingService.При вызове клиентом методов этого класса происходит упаковка вызова (и параметров) и их передача по сети серверному классу.
1 package com.asw.corba.ex2.BillingServiceModule;
2
3 /**
4 * com/asw/corba/ex2/BillingServiceModule/_BillingServiceStub.java.
5 * Generated by the IDL-to-Java compiler (portable), version "3.1"
6 * from com/asw/corba/ex2/BillingService.idl
7 * 16 Июль 2006 г. 15:01:11 MSD
8 */
9
10 // определение класса _BillingServiceStub
11 public class _BillingServiceStub extends org.omg.CORBA.
portable.ObjectImpl implements
com.asw.corba.ex2.BillingServiceModule.BillingService
12 {
13 public com.asw.corba.ex2.BillingServiceModule.Card getCard (String card)
14 {
15 org.omg.CORBA.portable.InputStream $in = null;
16 try {
17 org.omg.CORBA.portable.OutputStream $out =
_request ("getCard", true);
18 $out.write_string (card);
19 $in = _invoke ($out);
20 com.asw.corba.ex2.BillingServiceModule.Card $result =
com.asw.corba.ex2.BillingServiceModule.CardHelper.read ($in);
21 return $result;
22 } catch (org.omg.CORBA.portable.ApplicationException $ex) {
23 $in = $ex.getInputStream ();
24 String _id = $ex.getId ();
25 throw new org.omg.CORBA.MARSHAL (_id);
26 } catch (org.omg.CORBA.portable.RemarshalException $rm) {
27 return getCard (card );
28 } finally {
29 _releaseReply ($in);
30 }
31 } // getCard
32
33 public com.asw.corba.ex2.BillingServiceModule.Card addNewCard
(String personName, String card)
34 {
35 org.omg.CORBA.portable.InputStream $in = null;
36 try {
37 org.omg.CORBA.portable.OutputStream $out =
_request ("addNewCard", true);
38 $out.write_string (personName);
39 $out.write_string (card);
40 $in = _invoke ($out);
41 com.asw.corba.ex2.BillingServiceModule.Card $result =
com.asw.corba.ex2.BillingServiceModule.CardHelper.read ($in);
42 return $result;
43 } catch (org.omg.CORBA.portable.ApplicationException $ex) {
44 $in = $ex.getInputStream ();
45 String _id = $ex.getId ();
46 throw new org.omg.CORBA.MARSHAL (_id);
47 } catch (org.omg.CORBA.portable.RemarshalException $rm) {
48 return addNewCard (personName, card );
49 } finally {
50 _releaseReply ($in);
51 }
52 } // addNewCard
53
54 // Type-specific CORBA::Object operations
55 private static String[]__ids = {
56 "IDL:BillingServiceModule/BillingService:1.0"};
57 public String[] _ids ()
58 {
59 return (String[])__ids.clone ();
60 }
61
62 private void readObject (java.io.ObjectInputStream s)
throws java.io.IOException
63 {
64 String str = s.readUTF ();
65 String[] args = null;
66 java.util.Properties props = null;
67 org.omg.CORBA.Object obj = org.omg.CORBA.ORB.init
(args, props).string_to_object (str);
68 org.omg.CORBA.portable.Delegate delegate =
((org.omg.CORBA.portable.ObjectImpl) obj)._get_delegate ();
69 _set_delegate (delegate);
70 }
71
72 private void writeObject (java.io.ObjectOutputStream s)
throws java.io.IOException
73 {
74 String[] args = null;
75 java.util.Properties props = null;
76 String str = org.omg.CORBA.ORB.init (args, props).object_to_string
(this);
77 s.writeUTF (str);
78 }
79 } // class _BillingServiceStub
Листинг
8.6.
Класс BillingServiceStub, созданный idlj
И последний файл BillingServicePOA.java (пример 8.7) содержит класс, выполняющий всю техническую работу по диспетчеризации сообщений клиента, - этот класс будет являться предком для нашего серверного класса, в котором мы переопределим методы, выполняющие содержательные операции. Класс BillingServicePOA наследует от org.omg.PortableServer.Servant и реализует CORBA -интерфейс (InvokeHandler) и интерфейс BillingServiceOperations.Интерфейс InvokeHandler объявляет метод invoke, который является реализацией BillingServicePOA.
1 package com.asw.corba.ex2.BillingServiceModule;
2
3 /**
4 * com/asw/corba/ex2/BillingServiceModule/BillingServicePOA.java .
5 * Generated by the IDL-to-Java compiler (portable), version "3.1"
6 * from com/asw/corba/ex2/BillingService.idl
7 * 16 Июль 2006 г. 15:01:11 MSD
8 */
9
10 // определение класса BillingServicePOA
11 public abstract class BillingServicePOA extends
org.omg.PortableServer.Servant
12 implements
com.asw.corba.ex2.BillingServiceModule.BillingServiceOperations,
org.omg.CORBA.portable.InvokeHandler
13 {
14 // Constructors
15 private static java.util.Hashtable _methods = new java.util.Hashtable ();
16 static
17 {
18 _methods.put ("getCard", new java.lang.Integer (0));
19 _methods.put ("addNewCard", new java.lang.Integer (1));
20 }
21
22 public org.omg.CORBA.portable.OutputStream _invoke (String $method,
23 org.omg.CORBA.portable.InputStream in,
24 org.omg.CORBA.portable.ResponseHandler $rh)
25 {
26 org.omg.CORBA.portable.OutputStream out = null;
27 java.lang.Integer __method = (java.lang.Integer)_methods.get ($method);
28 if (__method == null)
29 throw new org.omg.CORBA.BAD_OPERATION (0,
org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);
30
31 switch __method.intValue ())
32 {
33 case 0: // BillingServiceModule/BillingService/getCard
34 {
35 String card = in.read_string ();
36 com.asw.corba.ex2.BillingServiceModule.Card $result = null;
37 $result = this.getCard (card);
38 out = $rh.createReply();
39 com.asw.corba.ex2.BillingServiceModule.CardHelper.write (out, $result);
40 break;
41 }
42
43 case 1: // BillingServiceModule/BillingService/addNewCard
44 {
45 String personName = in.read_string ();
46 String card = in.read_string ();
47 com.asw.corba.ex2.BillingServiceModule.Card $result = null;
48 $result = this.addNewCard (personName, card);
49 out = $rh.createReply();
50 com.asw.corba.ex2.BillingServiceModule.CardHelper.write (out, $result);
51 break;
52 }
53
54 default:
55 throw new org.omg.CORBA.BAD_OPERATION
(0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);
56 }
57 return out;
58 } // _invoke
59
60 // Type-specific CORBA::Object operations
61 private static String[] __ids =
{"IDL:BillingServiceModule/BillingService:1.0"};
62
63 public String[] _all_interfaces
(org.omg.PortableServer.POA poa, byte[] objectId)
64 {
65 return (String[]) __ids.clone ();
66 }
67
68 public BillingService _this()
69 {
70 return BillingServiceHelper.narrow(super._this_object());
71 }
72
73 public BillingService _this(org.omg.CORBA.ORB orb)
74 {
75 return BillingServiceHelper.narrow(super._this_object(orb));
76 }
77
78 } // class BillingServicePOA
Листинг
8.7.
Класс BillingServicePOA, созданный idlj