DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
ClientConnector.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 using System;
18 using System.Collections.Generic;
19 using System.Runtime.Remoting;
20 
21 using Deveel.Data.Routines;
22 using Deveel.Data.Sql.Triggers;
23 
24 namespace Deveel.Data.Protocol {
25  public abstract class ClientConnector : IClientConnector {
26  public void Dispose() {
27  Dispose(true);
28  GC.SuppressFinalize(this);
29  }
30 
31  protected virtual void Dispose(bool disposing) {
32 
33  }
34 
35  public ConnectorState CurrentState { get; private set; }
36 
37  public virtual ConnectionEndPoint LocalEndPoint { get; private set; }
38 
39  protected abstract ConnectionEndPoint MakeEndPoint(IDictionary<string, object> properties);
40 
41  ConnectionEndPoint IClientConnector.MakeEndPoint(IDictionary<string, object> properties) {
42  return MakeEndPoint(properties);
43  }
44 
46  return new ClientMessageProcessor(this);
47  }
48 
49  IMessageEnvelope IConnector.CreateEnvelope(IDictionary<string, object> metadata, IMessage message) {
50  return CreateEnvelope(metadata, message);
51  }
52 
53  protected abstract IMessageEnvelope CreateEnvelope(IDictionary<string, object> metadata, IMessage message);
54 
56  return CreateObjectChannel(objectId);
57  }
58 
59  protected abstract ILargeObjectChannel CreateObjectChannel(long objectId);
60 
61  ITriggerChannel IConnector.CreateTriggerChannel(string triggerName, string objectName, TriggerEventType eventType) {
62  return CreateTriggerChannel(triggerName, objectName, eventType);
63  }
64 
65  protected abstract ITriggerChannel CreateTriggerChannel(string triggerName, string objectName, TriggerEventType eventType);
66 
67  protected abstract IMessageEnvelope SendEnvelope(IMessageEnvelope envelope);
68 
69  protected virtual IMessage OpenEnvelope(IMessageEnvelope envelope) {
70  return envelope.Message;
71  }
72 
73  protected virtual void OnMessageReceived(IMessage message) {
74  }
75 
77  OnSetEncryption(encryptionData);
78  }
79 
80  protected virtual void OnSetEncryption(EncryptionData encryptionData) {
81  }
82 
84  private readonly ClientConnector connector;
85 
87  this.connector = connector;
88  }
89 
91  var response = connector.SendEnvelope(message);
92  if (response == null)
93  throw new InvalidOperationException("Unable to obtain a response from the server.");
94 
95  if (response.Error != null)
96  throw new ServerException(response.Error.ErrorMessage);
97 
98  var content = connector.OpenEnvelope(response);
99  connector.OnMessageReceived(content);
100  return response;
101  }
102  }
103  }
104 }
IMessageProcessor CreateProcessor()
TriggerEventType
The different types of high layer trigger events.
virtual void OnMessageReceived(IMessage message)
virtual void Dispose(bool disposing)
IMessageEnvelope CreateEnvelope(IDictionary< string, object > metadata, IMessage message)
IMessageEnvelope ProcessMessage(IMessageEnvelope message)
ConnectionEndPoint MakeEndPoint(IDictionary< string, object > properties)
ITriggerChannel CreateTriggerChannel(string triggerName, string objectName, TriggerEventType eventType)
virtual IMessage OpenEnvelope(IMessageEnvelope envelope)
virtual void OnSetEncryption(EncryptionData encryptionData)
void SetEncrypton(EncryptionData encryptionData)
ILargeObjectChannel CreateObjectChannel(long objectId)