|
Прохожу курс "Построение распределенных систем на Java" в третьей лекции где описывается TCPServer вылетает эта ошибка
"Connection cannot be resolved to a type" Java version 1.7.0_05 |
Использование CORBA
Автоматически сгенерированные файлы
После компиляции файла BillingService.idl компилятор Java-IDL создает следующие файлы на стороне сервера в вновь созданной директории BillingServiceModule:
BillingService.java, BillingServiceHelper.java, BillingServiceHolder.java, BillingServiceOperations.java, BillingServicePOA.java, _BillingServiceStub.java.
Рассмотрим подробнее эти файлы (в этих файлах определены классы и интерфейсы) и то, как мы можем их использовать при создании нашего приложения.
BillingService.java и BillingServiceOperations.java - интерфейсы. BillingService.java (пример 6.2) представляет собой интерфейс BillingService.
1 package com.asw.corba.ex1.BillingServiceModule;
2
3
4 /**
5 * com/asw/corba/ex1/BillingServiceModule/BillingService.java .
6 * Generated by the IDL-to-Java compiler (portable), version "3.1"
7 * from com/asw/corba/ex1/BillingService.idl
8 * 16 Июль 2006 г. 14:12:21 MSD
9 */
10
11 public interface BillingService extends BillingServiceOperations,
12 org.omg.CORBA.Object, org.omg.CORBA.portable.IDLEntity
13 {
14 } // interface BillingService
Листинг
6.2.
Интерфейс BillingService, созданный idlj
В строках 11 и 12 объявлен интерфейс BillingService и три интерфейса, от которых наследует BillingService. Два из трех интерфейсов являются определенными в CORBA типами, от которых должны наследовать все CORBA -совместимые объекты, org.omg.CORBA.Object и org.omg.CORBA.portable. IDLEntity.Третий интерфейс - BillingServiceOperations (пример 6.3) - создается на основе IDL -описания и объявляет открытые операции данного сервера. BillingService определяет базовый класс, который наследует от BillingServiceOperations и от CORBA -интерфейсов, упомянутых ранее. Это часть структуры, необходимой производным классам, чтобы быть настоящими CORBA -объектами. BillingServiceOperations,ни от кого не наследуя, объявляет четыре метода, изначально определенные в IDL.
1 package com.asw.corba.ex1.BillingServiceModule;
2
3
4 /**
5 * com/asw/corba/ex1/BillingServiceModule/BillingServiceOperations.java .
6 * Generated by the IDL-to-Java compiler (portable), version "3.1"
7 * from com/asw/corba/ex1/BillingService.idl
8 * 16 Июль 2006 г. 14:12:21 MSD
9 */
10
11 // определение CORBA-совместимого сервиса
12 public interface BillingServiceOperations
13 {
14 void addNewCard (String personName, String card);
15 void addMoney (String card, double money);
16 void subMoney (String card, double money);
17 double getCardBalance (String card);
18 } // interface BillingServiceOperations
Листинг
6.3.
Интерфейс BillingServiceOperations, созданный idlj
Файлы BillingServiceHelper.java (пример 6.4) и BillingServiceHolder.java (пример 6.5) содержат вспомогательные классы, содержащие методы приведения типов и методы маршаллинга/демаршаллинга сообщений.
1 package com.asw.corba.ex1.BillingServiceModule;
2
3
4 /**
5 * com/asw/corba/ex1/BillingServiceModule/BillingServiceHelper.java .
6 * Generated by the IDL-to-Java compiler (portable), version "3.1"
7 * from com/asw/corba/ex1/BillingService.idl
8 * 16 Июль 2006 г. 14:12:21 MSD
9 */
10
11 // определение класса BillingServiceHelper
12 abstract public class BillingServiceHelper
13 {
14 private static String _id =
"IDL:BillingServiceModule/BillingService:1.0";
15
16 public static void insert (org.omg.CORBA.Any a,
com.asw.corba.ex1.BillingServiceModule.BillingService that)
17 {
18 org.omg.CORBA.portable.OutputStream out = a.create_output_stream ();
19 a.type (type ());
20 write (out, that);
21 a.read_value (out.create_input_stream (), type ());
22 }
23
24 public static com.asw.corba.ex1.BillingServiceModule.BillingService
extract (org.omg.CORBA.Any a)
25 {
26 return read (a.create_input_stream ());
27 }
28
29 private static org.omg.CORBA.TypeCode __typeCode = null;
30 synchronized public static org.omg.CORBA.TypeCode type ()
31 {
32 if (__typeCode == null)
33 {
34 __typeCode = org.omg.CORBA.ORB.init ().create_interface_tc
(com.asw.corba.ex1.BillingServiceModule.BillingServiceHelper.id (),
"BillingService");
35 }
36 return__typeCode;
37 }
38
39 public static String id ()
40 {
41 return _id;
42 }
43
44 public static com.asw.corba.ex1.BillingServiceModule.BillingService
read (org.omg.CORBA.portable.InputStream istream)
45 {
46 return narrow (istream.read_Object (_BillingServiceStub.class));
47 }
48
49 public static void write (org.omg.CORBA.portable.OutputStream
ostream, com.asw.corba.ex1.BillingServiceModule.BillingService
value)
50 {
51 ostream.write_Object ((org.omg.CORBA.Object) value);
52 }
53
54 public static com.asw.corba.ex1.BillingServiceModule.BillingService
narrow (org.omg.CORBA.Object obj)
55 {
56 if (obj == null)
57 return null;
58 else if (obj instanceof
com.asw.corba.ex1.BillingServiceModule.BillingService)
59 return (com.asw.corba.ex1.BillingServiceModule.BillingService)obj;
60 else if (!obj._is_a (id ()))
61 throw new org.omg.CORBA.BAD_PARAM ();
62 else
63 {
64 org.omg.CORBA.portable.Delegate delegate =
((org.omg.CORBA.portab-le.ObjectImpl)obj)._get_delegate ();
65 com.asw.corba.ex1.BillingServiceModule._BillingServiceStub stub =
new com.asw.corba.ex1.BillingServiceModule._BillingServiceStub ();
66 stub._set_delegate(delegate);
67 return stub;
68 }
69 }
70 }
Листинг
6.4.
Класс BillingServiceHelper, созданный idlj
Необходимость в Holder -классах возникает в тот момент, когда у методов появляются возвращаемые параметры.
1 package com.asw.corba.ex1.BillingServiceModule;
2
3 /**
4 * com/asw/corba/ex1/BillingServiceModule/BillingServiceHolder.java
5 * Generated by the IDL-to-Java compiler (portable), version "3.1"
6 * from com/asw/corba/ex1/BillingService.idl
7 * 16 Июль 2006 г. 14:12:21 MSD
8 */
9
10 // определение класса BillingServiceHolder
11 public final class BillingServiceHolder implements
org.omg.CORBA.portable.Streamable
12 {
13 public com.asw.corba.ex1.BillingServiceModule.BillingService value
= null;
14
15 public BillingServiceHolder ()
16 {
17 }
18
19 public BillingServiceHolder (com.asw.corba.ex1.
BillingServiceModule.BillingService initialValue)
20 {
21 value = initialValue;
22 } 23
24 public void _read (org.omg.CORBA.portable.InputStream i)
25 {
26 value = com.asw.corba.ex1.BillingServiceModule.
BillingServiceHelper.read (i);
27 }
28
29 public void _write (org.omg.CORBA.portable.OutputStream o)
30 {
31 com.asw.corba.ex1.BillingServiceModule.BillingServiceHelper.write
(o, value);
32 }
33
34 public org.omg.CORBA.TypeCode _type ()
35 {
36 return com.asw.corba.ex1.BillingServiceModule.
BillingServiceHelper.type ();
37 }
38
39 }
Листинг
6.5.
Класс BillingServiceHolder, созданный idlj