DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | Protected Member Functions | Properties | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
Deveel.Data.Protocol.Processor Class Referenceabstract

This processes _queries from a client and dispatches the _queries to the database. More...

Inheritance diagram for Deveel.Data.Protocol.Processor:

Public Member Functions

abstract void Close ()
 Closes the connection with the client. More...
 
void Dispose ()
 

Protected Member Functions

 Processor (DbController controller, string hostString)
 
byte[] ProcessCommand (byte[] command)
 Processes a single Query from the client. More...
 
void Dispose (bool disposing)
 Disposes of this processor. More...
 
abstract void SendEvent (byte[] eventMsg)
 Sends an event to the client. More...
 

Properties

ClientConnectionState ClientState [get]
 Returns the state of the connection. More...
 
abstract bool IsClosed [get]
 Returns true if the connection to the client is closed. More...
 
IDatabase Database [get, private set]
 

Private Member Functions

void OnDatabaseEvent (int eventType, String eventMessage)
 
bool ChangeDatabaseInterface (IDbConfig config, string databaseName)
 
byte[] ProcessQuery (byte[] command)
 Processes a query on the byte[] array and returns the result. More...
 
byte[] ChangeDatabase (int dispatchId, byte[] command)
 
byte[] QueryCommand (int dispatchId, byte[] command)
 Executes a query and returns the header for the result in the response. More...
 
byte[] PushStreamableObjectPart (int dispatchId, byte[] command)
 Pushes a part of a streamable object onto the server. More...
 
byte[] ResultSection (int dispatchId, byte[] command)
 Responds with a part of the result set of a query made via the ProtocolConstants.Query Query. More...
 
byte[] StreamableObjectSection (int dispatchId, byte[] command)
 Returns a section of a streamable object. More...
 
byte[] DisposeStreamableObject (int dispatchId, byte[] command)
 Disposes of a streamable object. More...
 
byte[] DisposeResult (int dispatchId, byte[] command)
 Disposes of a result set we queries via the ProtocolConstants.Query Query. More...
 
 ~Processor ()
 

Static Private Member Functions

static byte[] Single (int val)
 Returns a single 4 byte array with the given int encoded into it. More...
 
static byte[] Exception (int dispatchId, DataException e)
 Creates a response that represents a data exception failure. More...
 
static byte[] SimpleSuccess (int dispatchId)
 Creates a response that indicates a simple success of an operation with the given dispatch id. More...
 

Private Attributes

const int ServerVersion = 1
 The version of the server protocol. More...
 
ClientConnectionState state
 The current state we are in. More...
 
int authenticationTries
 Number of authentications tried. More...
 
readonly string hostString
 
readonly DbController controller
 
readonly Dictionary< string, DatabaseInterface > dbInterfaces
 
DatabaseInterface dbInterface
 
readonly DatabaseEventCallback dbCallback
 The database call back method that sends database events back to the client. More...
 

Detailed Description

This processes _queries from a client and dispatches the _queries to the database.

This is a state based class. There is a single processor for each client connected. This class is designed to be flexible enough to handle packet based protocols as well as stream based protocols.

Definition at line 41 of file Processor.cs.

Constructor & Destructor Documentation

Deveel.Data.Protocol.Processor.Processor ( DbController  controller,
string  hostString 
)
inlineprotected

Definition at line 63 of file Processor.cs.

63  {
64  this.hostString = hostString;
65  dbInterfaces = new Dictionary<string, DatabaseInterface>();
66  this.controller = controller;
67  state = 0;
70  }
readonly DbController controller
Definition: Processor.cs:59
readonly DatabaseEventCallback dbCallback
The database call back method that sends database events back to the client.
Definition: Processor.cs:90
readonly Dictionary< string, DatabaseInterface > dbInterfaces
Definition: Processor.cs:60
int authenticationTries
Number of authentications tried.
Definition: Processor.cs:55
ClientConnectionState state
The current state we are in.
Definition: Processor.cs:50
readonly string hostString
Definition: Processor.cs:57
void OnDatabaseEvent(int eventType, String eventMessage)
Definition: Processor.cs:72
Deveel.Data.Protocol.Processor.~Processor ( )
inlineprivate

Definition at line 554 of file Processor.cs.

554  {
555  Dispose(false);
556  }

Member Function Documentation

byte [] Deveel.Data.Protocol.Processor.ChangeDatabase ( int  dispatchId,
byte[]  command 
)
inlineprivate

Definition at line 319 of file Processor.cs.

319  {
320  // Read the query from the Query.
321  MemoryStream input = new MemoryStream(command, 8, command.Length - 8);
322  BinaryReader reader = new BinaryReader(input, Encoding.Unicode);
323 
324  string databaseName = reader.ReadString();
325 
326  try {
327  dbInterface.ChangeDatabase(databaseName);
328  state = ClientConnectionState.NotAuthenticated;
329  return SimpleSuccess(dispatchId);
330  } catch (DataException e) {
331  return Exception(dispatchId, e);
332  }
333  }
static byte[] Exception(int dispatchId, DataException e)
Creates a response that represents a data exception failure.
Definition: Processor.cs:214
DatabaseInterface dbInterface
Definition: Processor.cs:61
static byte[] SimpleSuccess(int dispatchId)
Creates a response that indicates a simple success of an operation with the given dispatch id...
Definition: Processor.cs:248
ClientConnectionState state
The current state we are in.
Definition: Processor.cs:50
bool Deveel.Data.Protocol.Processor.ChangeDatabaseInterface ( IDbConfig  config,
string  databaseName 
)
inlineprivate

Definition at line 92 of file Processor.cs.

92  {
93  if (!controller.DatabaseExists(config, databaseName))
94  return false;
95 
96  DatabaseInterface dbi;
97  if (!dbInterfaces.TryGetValue(databaseName, out dbi)) {
98  dbi = new DatabaseInterface(controller, databaseName, hostString);
99  dbInterfaces[databaseName] = dbi;
100  }
101 
102  Database = controller.GetDatabase(databaseName);
103  dbInterface = dbi;
104  return true;
105  }
readonly DbController controller
Definition: Processor.cs:59
readonly Dictionary< string, DatabaseInterface > dbInterfaces
Definition: Processor.cs:60
DatabaseInterface dbInterface
Definition: Processor.cs:61
readonly string hostString
Definition: Processor.cs:57
abstract void Deveel.Data.Protocol.Processor.Close ( )
pure virtual

Closes the connection with the client.

void Deveel.Data.Protocol.Processor.Dispose ( bool  disposing)
inlineprotected

Disposes of this processor.

Definition at line 301 of file Processor.cs.

301  {
302  if (disposing) {
303  try {
304  if (dbInterfaces.Count > 0) {
305  foreach (DatabaseInterface databaseInterface in dbInterfaces.Values) {
306  databaseInterface.Dispose();
307  }
308  }
309  dbInterfaces.Clear();
310  } catch (Exception e) {
311  controller.Logger.Error(this, e);
312  }
313  }
314  }
readonly DbController controller
Definition: Processor.cs:59
static byte[] Exception(int dispatchId, DataException e)
Creates a response that represents a data exception failure.
Definition: Processor.cs:214
readonly Dictionary< string, DatabaseInterface > dbInterfaces
Definition: Processor.cs:60
void Deveel.Data.Protocol.Processor.Dispose ( )
inline

Definition at line 558 of file Processor.cs.

558  {
559  Dispose(true);
560  GC.SuppressFinalize(this);
561  }
byte [] Deveel.Data.Protocol.Processor.DisposeResult ( int  dispatchId,
byte[]  command 
)
inlineprivate

Disposes of a result set we queries via the ProtocolConstants.Query Query.

Parameters
dispatchId
command
Returns

Definition at line 507 of file Processor.cs.

507  {
508  // Get the result id.
509  int resultId = ByteBuffer.ReadInt4(command, 8);
510 
511  try {
512  // Dispose the table.
513  dbInterface.DisposeResult(resultId);
514  // Return operation success.
515  return SimpleSuccess(dispatchId);
516  } catch (DataException e) {
517  return Exception(dispatchId, e);
518  }
519  }
int ReadInt4()
Reads an integer from the buffer at the current position.
Definition: ByteBuffer.cs:128
static byte[] Exception(int dispatchId, DataException e)
Creates a response that represents a data exception failure.
Definition: Processor.cs:214
DatabaseInterface dbInterface
Definition: Processor.cs:61
static byte[] SimpleSuccess(int dispatchId)
Creates a response that indicates a simple success of an operation with the given dispatch id...
Definition: Processor.cs:248
A wrapper for an array of byte.
Definition: ByteBuffer.cs:27
byte [] Deveel.Data.Protocol.Processor.DisposeStreamableObject ( int  dispatchId,
byte[]  command 
)
inlineprivate

Disposes of a streamable object.

Parameters
dispatchId
command
Returns

Definition at line 486 of file Processor.cs.

486  {
487  int resultId = ByteBuffer.ReadInt4(command, 8);
488  long streamableObjectId = ByteBuffer.ReadInt8(command, 12);
489 
490  try {
491  // Pass this through to the underlying database interface.
492  dbInterface.DisposeStreamableObject(resultId, streamableObjectId);
493 
494  // Return operation success.
495  return SimpleSuccess(dispatchId);
496  } catch (DataException e) {
497  return Exception(dispatchId, e);
498  }
499  }
int ReadInt4()
Reads an integer from the buffer at the current position.
Definition: ByteBuffer.cs:128
static byte[] Exception(int dispatchId, DataException e)
Creates a response that represents a data exception failure.
Definition: Processor.cs:214
DatabaseInterface dbInterface
Definition: Processor.cs:61
static byte[] SimpleSuccess(int dispatchId)
Creates a response that indicates a simple success of an operation with the given dispatch id...
Definition: Processor.cs:248
A wrapper for an array of byte.
Definition: ByteBuffer.cs:27
static long ReadInt8(byte[] arr, int offset)
Definition: ByteBuffer.cs:234
static byte [] Deveel.Data.Protocol.Processor.Exception ( int  dispatchId,
DataException  e 
)
inlinestaticprivate

Creates a response that represents a data exception failure.

Parameters
dispatchId
e
Returns

Definition at line 214 of file Processor.cs.

214  {
215  int code = /* TODO: e.ErrorCode */ -1;
216  string msg = e.Message;
217  if (String.IsNullOrEmpty(msg))
218  msg = "NULL exception message";
219 
220  string server_msg = "";
221  string stack_trace = "";
222 
223  if (e is DbDataException) {
224  DbDataException me = (DbDataException)e;
225  server_msg = me.ServerErrorMessage;
226  stack_trace = me.ServerErrorStackTrace;
227  } else {
228  stack_trace = e.StackTrace;
229  }
230 
231  MemoryStream output = new MemoryStream();
232  BinaryWriter writer = new BinaryWriter(output, Encoding.Unicode);
233  writer.Write(dispatchId);
234  writer.Write(ProtocolConstants.Exception);
235  writer.Write(code);
236  writer.Write(msg);
237  writer.Write(stack_trace);
238 
239  return output.ToArray();
240  }
A long string in the system.
void Deveel.Data.Protocol.Processor.OnDatabaseEvent ( int  eventType,
String  eventMessage 
)
inlineprivate

Definition at line 72 of file Processor.cs.

72  {
73  try {
74  // Format the call back and send the event.
75  MemoryStream bout = new MemoryStream();
76  BinaryWriter dout = new BinaryWriter(bout, Encoding.Unicode);
77  dout.Write(eventType);
78  dout.Write(eventMessage);
79  SendEvent(bout.ToArray());
80  } catch (IOException e) {
81  controller.Logger.Error(this, "IO Error: " + e.Message);
82  controller.Logger.Error(this, e);
83  }
84  }
abstract void SendEvent(byte[] eventMsg)
Sends an event to the client.
readonly DbController controller
Definition: Processor.cs:59
byte [] Deveel.Data.Protocol.Processor.ProcessCommand ( byte[]  command)
inlineprotected

Processes a single Query from the client.

Parameters
command
Returns
Returns a byte array and the response is written out as a byte array, or null if the connection has been closed.

Definition at line 115 of file Processor.cs.

115  {
116  if (state == ClientConnectionState.Closed) {
117  // State 0 means we looking for the header...
118  BinaryReader reader = new BinaryReader(new MemoryStream(command), Encoding.ASCII);
119  /*
120  int magic = ByteBuffer.ReadInt4(Query, 0);
121  // The driver version number
122  int maj_ver = ByteBuffer.ReadInt4(Query, 4);
123  int min_ver = ByteBuffer.ReadInt4(Query, 8);
124  */
125  reader.ReadInt32(); // magic
126  reader.ReadInt32(); // server major version
127  reader.ReadInt32(); // server minor version
128 
129  string databaseName = reader.ReadString();
130 
131  if (!ChangeDatabaseInterface(controller.Config, databaseName))
132  return Single(ProtocolConstants.DatabaseNotFound);
133 
134  Version version = Assembly.GetExecutingAssembly().GetName().Version;
135 
136  byte[] ackCommand = new byte[4 + 1 + 4 + 4 + 1];
137  // Send back an acknowledgement and the version number of the server
138  ByteBuffer.WriteInteger(ProtocolConstants.Acknowledgement, ackCommand, 0);
139  ackCommand[4] = 1;
140  ByteBuffer.WriteInteger(version.Major, ackCommand, 5);
141  ByteBuffer.WriteInteger(version.Minor, ackCommand, 9);
142  ackCommand[13] = 0;
143 
144  // Set to the next state.
145  state = ClientConnectionState.NotAuthenticated;
146 
147  // Return the acknowledgement
148  return ackCommand;
149  }
150 
151  if (state == ClientConnectionState.NotAuthenticated) {
152  // State 4 means we looking for username and password...
153  MemoryStream input = new MemoryStream(command);
154  BinaryReader reader = new BinaryReader(input, Encoding.ASCII);
155  string defaultSchema = reader.ReadString();
156  string username = reader.ReadString();
157  string password = reader.ReadString();
158 
159  try {
160  if (!dbInterface.Login(defaultSchema, username, password, dbCallback)) {
161  // Close after 12 tries.
162  if (authenticationTries >= 12) {
163  Close();
164  } else {
166  return Single(ProtocolConstants.UserAuthenticationFailed);
167  }
168  } else {
169  state = ClientConnectionState.Processing;
170  return Single(ProtocolConstants.UserAuthenticationPassed);
171  }
172  } catch (DataException) {
173 
174  }
175 
176  return null;
177  }
178 
179  if (state == ClientConnectionState.Processing)
180  // Process the query
181  return ProcessQuery(command);
182 
183  throw new Exception("Illegal state: " + state);
184  }
readonly DbController controller
Definition: Processor.cs:59
readonly DatabaseEventCallback dbCallback
The database call back method that sends database events back to the client.
Definition: Processor.cs:90
ByteBuffer WriteInteger(int v)
Writes an integer into the buffer at the current position.
Definition: ByteBuffer.cs:118
static byte[] Single(int val)
Returns a single 4 byte array with the given int encoded into it.
Definition: Processor.cs:202
bool ChangeDatabaseInterface(IDbConfig config, string databaseName)
Definition: Processor.cs:92
static byte[] Exception(int dispatchId, DataException e)
Creates a response that represents a data exception failure.
Definition: Processor.cs:214
byte[] ProcessQuery(byte[] command)
Processes a query on the byte[] array and returns the result.
Definition: Processor.cs:260
int authenticationTries
Number of authentications tried.
Definition: Processor.cs:55
DatabaseInterface dbInterface
Definition: Processor.cs:61
A wrapper for an array of byte.
Definition: ByteBuffer.cs:27
ClientConnectionState state
The current state we are in.
Definition: Processor.cs:50
abstract void Close()
Closes the connection with the client.
byte [] Deveel.Data.Protocol.Processor.ProcessQuery ( byte[]  command)
inlineprivate

Processes a query on the byte[] array and returns the result.

Parameters
command
Returns

Definition at line 260 of file Processor.cs.

260  {
261  byte[] result;
262 
263  // The first int is the Query.
264  int ins = ByteBuffer.ReadInt4(command, 0);
265 
266  // Otherwise must be a dispatch type request.
267  // The second is the dispatch id.
268  int dispatchId = ByteBuffer.ReadInt4(command, 4);
269 
270  if (dispatchId == -1)
271  throw new Exception("Special case dispatch id of -1 in query");
272 
273  if (ins == ProtocolConstants.ChangeDatabase) {
274  result = ChangeDatabase(dispatchId, command);
275  } else if (ins == ProtocolConstants.ResultSection) {
276  result = ResultSection(dispatchId, command);
277  } else if (ins == ProtocolConstants.Query) {
278  result = QueryCommand(dispatchId, command);
279  } else if (ins == ProtocolConstants.PushStreamableObjectPart) {
280  result = PushStreamableObjectPart(dispatchId, command);
281  } else if (ins == ProtocolConstants.DisposeResult) {
282  result = DisposeResult(dispatchId, command);
283  } else if (ins == ProtocolConstants.StreamableObjectSection) {
284  result = StreamableObjectSection(dispatchId, command);
285  } else if (ins == ProtocolConstants.DisposeStreamableObject) {
286  result = DisposeStreamableObject(dispatchId, command);
287  } else if (ins == ProtocolConstants.Close) {
288  Close();
289  result = null;
290  } else {
291  throw new Exception("Query (" + ins + ") not understood.");
292  }
293 
294  return result;
295 
296  }
byte[] ChangeDatabase(int dispatchId, byte[] command)
Definition: Processor.cs:319
int ReadInt4()
Reads an integer from the buffer at the current position.
Definition: ByteBuffer.cs:128
byte[] DisposeStreamableObject(int dispatchId, byte[] command)
Disposes of a streamable object.
Definition: Processor.cs:486
static byte[] Exception(int dispatchId, DataException e)
Creates a response that represents a data exception failure.
Definition: Processor.cs:214
byte[] StreamableObjectSection(int dispatchId, byte[] command)
Returns a section of a streamable object.
Definition: Processor.cs:455
byte[] ResultSection(int dispatchId, byte[] command)
Responds with a part of the result set of a query made via the ProtocolConstants.Query Query...
Definition: Processor.cs:417
byte[] DisposeResult(int dispatchId, byte[] command)
Disposes of a result set we queries via the ProtocolConstants.Query Query.
Definition: Processor.cs:507
byte[] PushStreamableObjectPart(int dispatchId, byte[] command)
Pushes a part of a streamable object onto the server.
Definition: Processor.cs:389
A wrapper for an array of byte.
Definition: ByteBuffer.cs:27
byte[] QueryCommand(int dispatchId, byte[] command)
Executes a query and returns the header for the result in the response.
Definition: Processor.cs:346
abstract void Close()
Closes the connection with the client.
byte [] Deveel.Data.Protocol.Processor.PushStreamableObjectPart ( int  dispatchId,
byte[]  command 
)
inlineprivate

Pushes a part of a streamable object onto the server.

Parameters
dispatchIdThe number we need to respond with.
command
Returns

Definition at line 389 of file Processor.cs.

389  {
390  ReferenceType type = (ReferenceType) command[8];
391  long objectId = ByteBuffer.ReadInt8(command, 9);
392  long objectLength = ByteBuffer.ReadInt8(command, 17);
393  int length = ByteBuffer.ReadInt4(command, 25);
394  byte[] obBuf = new byte[length];
395  Array.Copy(command, 29, obBuf, 0, length);
396  long offset = ByteBuffer.ReadInt8(command, 29 + length);
397 
398  try {
399  // Pass this through to the underlying database interface.
400  dbInterface.PushStreamableObjectPart(type, objectId, objectLength, obBuf, offset, length);
401 
402  // Return operation success.
403  return SimpleSuccess(dispatchId);
404  } catch (DataException e) {
405  return Exception(dispatchId, e);
406  }
407  }
int ReadInt4()
Reads an integer from the buffer at the current position.
Definition: ByteBuffer.cs:128
static byte[] Exception(int dispatchId, DataException e)
Creates a response that represents a data exception failure.
Definition: Processor.cs:214
DatabaseInterface dbInterface
Definition: Processor.cs:61
static byte[] SimpleSuccess(int dispatchId)
Creates a response that indicates a simple success of an operation with the given dispatch id...
Definition: Processor.cs:248
A wrapper for an array of byte.
Definition: ByteBuffer.cs:27
static long ReadInt8(byte[] arr, int offset)
Definition: ByteBuffer.cs:234
byte [] Deveel.Data.Protocol.Processor.QueryCommand ( int  dispatchId,
byte[]  command 
)
inlineprivate

Executes a query and returns the header for the result in the response.

Parameters
dispatchIdThe number we need to respond with.
command

This keeps track of all result sets because sections of the result are later queries via the ProtocolConstants.ResultSection Query.

Returns

Definition at line 346 of file Processor.cs.

346  {
347  // Read the query from the Query.
348  MemoryStream input = new MemoryStream(command, 8, command.Length - 8);
349  BinaryReader reader = new BinaryReader(input, Encoding.Unicode);
350  SqlQuery query = SqlQuery.ReadFrom(reader);
351 
352  try {
353  // Do the query
354  IQueryResponse response = dbInterface.ExecuteQuery(query)[0];
355 
356  // Prepare the stream to output the response to,
357  MemoryStream output = new MemoryStream();
358  BinaryWriter writer = new BinaryWriter(output, Encoding.Unicode);
359 
360  writer.Write(dispatchId);
361  writer.Write(ProtocolConstants.Success);
362 
363  // The response sends the result id, the time the query took, the
364  // total row count, and description of each column in the result.
365  writer.Write(response.ResultId);
366  writer.Write(response.QueryTimeMillis);
367  writer.Write(response.RowCount);
368  int colCount = response.ColumnCount;
369  writer.Write(colCount);
370  for (int i = 0; i < colCount; ++i) {
371  response.GetColumnDescription(i).WriteTo(writer);
372  }
373  writer.Flush();
374  return output.ToArray();
375  } catch (DataException e) {
376  // debug.writeException(e);
377  return Exception(dispatchId, e);
378  }
379 
380  }
static byte[] Exception(int dispatchId, DataException e)
Creates a response that represents a data exception failure.
Definition: Processor.cs:214
DatabaseInterface dbInterface
Definition: Processor.cs:61
byte [] Deveel.Data.Protocol.Processor.ResultSection ( int  dispatchId,
byte[]  command 
)
inlineprivate

Responds with a part of the result set of a query made via the ProtocolConstants.Query Query.

Parameters
dispatchIdThe number we need to respond with.
command
Returns

Definition at line 417 of file Processor.cs.

417  {
418  int resultId = ByteBuffer.ReadInt4(command, 8);
419  int rowNumber = ByteBuffer.ReadInt4(command, 12);
420  int rowCount = ByteBuffer.ReadInt4(command, 16);
421 
422  try {
423  // Get the result part...
424  ResultPart block = dbInterface.GetResultPart(resultId, rowNumber, rowCount);
425 
426  MemoryStream output = new MemoryStream();
427  BinaryWriter writer = new BinaryWriter(output, Encoding.Unicode);
428 
429  writer.Write(dispatchId);
430  writer.Write(ProtocolConstants.Success);
431 
432  // Send the contents of the result set.
433  // HACK - Work out column count by dividing number of entries in block
434  // by number of rows.
435  int colCount = block.Count / rowCount;
436  writer.Write(colCount);
437  int bsize = block.Count;
438  for (int index = 0; index < bsize; ++index) {
439  ObjectTransfer.WriteTo(writer, block[index]);
440  }
441 
442  writer.Flush();
443  return output.ToArray();
444  } catch (DataException e) {
445  return Exception(dispatchId, e);
446  }
447  }
int ReadInt4()
Reads an integer from the buffer at the current position.
Definition: ByteBuffer.cs:128
static byte[] Exception(int dispatchId, DataException e)
Creates a response that represents a data exception failure.
Definition: Processor.cs:214
DatabaseInterface dbInterface
Definition: Processor.cs:61
A wrapper for an array of byte.
Definition: ByteBuffer.cs:27
abstract void Deveel.Data.Protocol.Processor.SendEvent ( byte[]  eventMsg)
protectedpure virtual

Sends an event to the client.

Parameters
eventMsg

This is used to notify the client of trigger events, etc.

Security Issue: This is always invoked by the DatabaseDispatcher. We have to be careful that this method isn't allowed to block. Otherwise the DatabaseDispatcher thread will be out of operation. Unfortunately assuring this may not be possible until non-blocking IO, or we use datagrams for transmission. I know for sure that the TCP implementation is vunrable. If the client doesn't 'read' what we are sending then this'll block when the buffers become full.

static byte [] Deveel.Data.Protocol.Processor.SimpleSuccess ( int  dispatchId)
inlinestaticprivate

Creates a response that indicates a simple success of an operation with the given dispatch id.

Parameters
dispatchId
Returns

Definition at line 248 of file Processor.cs.

248  {
249  byte[] buf = new byte[8];
250  ByteBuffer.WriteInteger(dispatchId, buf, 0);
251  ByteBuffer.WriteInteger(ProtocolConstants.Success, buf, 4);
252  return buf;
253  }
ByteBuffer WriteInteger(int v)
Writes an integer into the buffer at the current position.
Definition: ByteBuffer.cs:118
A wrapper for an array of byte.
Definition: ByteBuffer.cs:27
static byte [] Deveel.Data.Protocol.Processor.Single ( int  val)
inlinestaticprivate

Returns a single 4 byte array with the given int encoded into it.

Parameters
val
Returns

Definition at line 202 of file Processor.cs.

202  {
203  byte[] buf = new byte[4];
204  ByteBuffer.WriteInteger(val, buf, 0);
205  return buf;
206  }
ByteBuffer WriteInteger(int v)
Writes an integer into the buffer at the current position.
Definition: ByteBuffer.cs:118
A wrapper for an array of byte.
Definition: ByteBuffer.cs:27
byte [] Deveel.Data.Protocol.Processor.StreamableObjectSection ( int  dispatchId,
byte[]  command 
)
inlineprivate

Returns a section of a streamable object.

Parameters
dispatchIdThe number we need to respond with.
command
Returns

Definition at line 455 of file Processor.cs.

455  {
456  int resultId = ByteBuffer.ReadInt4(command, 8);
457  long streamableObjectId = ByteBuffer.ReadInt8(command, 12);
458  long offset = ByteBuffer.ReadInt8(command, 20);
459  int length = ByteBuffer.ReadInt4(command, 28);
460 
461  try {
462  byte[] buf = dbInterface.GetStreamableObjectPart(resultId, streamableObjectId, offset, length);
463 
464  MemoryStream output = new MemoryStream();
465  BinaryWriter writer = new BinaryWriter(output, Encoding.Unicode);
466 
467  writer.Write(dispatchId);
468  writer.Write(ProtocolConstants.Success);
469 
470  writer.Write(buf.Length);
471  writer.Write(buf, 0, buf.Length);
472  writer.Flush();
473  return output.ToArray();
474  } catch (DataException e) {
475  return Exception(dispatchId, e);
476  }
477 
478  }
int ReadInt4()
Reads an integer from the buffer at the current position.
Definition: ByteBuffer.cs:128
static byte[] Exception(int dispatchId, DataException e)
Creates a response that represents a data exception failure.
Definition: Processor.cs:214
DatabaseInterface dbInterface
Definition: Processor.cs:61
A wrapper for an array of byte.
Definition: ByteBuffer.cs:27
static long ReadInt8(byte[] arr, int offset)
Definition: ByteBuffer.cs:234

Member Data Documentation

int Deveel.Data.Protocol.Processor.authenticationTries
private

Number of authentications tried.

Definition at line 55 of file Processor.cs.

readonly DbController Deveel.Data.Protocol.Processor.controller
private

Definition at line 59 of file Processor.cs.

readonly DatabaseEventCallback Deveel.Data.Protocol.Processor.dbCallback
private

The database call back method that sends database events back to the client.

Definition at line 90 of file Processor.cs.

DatabaseInterface Deveel.Data.Protocol.Processor.dbInterface
private

Definition at line 61 of file Processor.cs.

readonly Dictionary<string, DatabaseInterface> Deveel.Data.Protocol.Processor.dbInterfaces
private

Definition at line 60 of file Processor.cs.

readonly string Deveel.Data.Protocol.Processor.hostString
private

Definition at line 57 of file Processor.cs.

const int Deveel.Data.Protocol.Processor.ServerVersion = 1
private

The version of the server protocol.

Definition at line 45 of file Processor.cs.

ClientConnectionState Deveel.Data.Protocol.Processor.state
private

The current state we are in.

Definition at line 50 of file Processor.cs.

Property Documentation

ClientConnectionState Deveel.Data.Protocol.Processor.ClientState
getprotected

Returns the state of the connection.

0 = not logged in yet. 1 = logged in.

Definition at line 192 of file Processor.cs.

IDatabase Deveel.Data.Protocol.Processor.Database
getprivate set

Definition at line 551 of file Processor.cs.

abstract bool Deveel.Data.Protocol.Processor.IsClosed
get

Returns true if the connection to the client is closed.

Definition at line 549 of file Processor.cs.


The documentation for this class was generated from the following file: