{
return Boolean.FALSE;
}
else if (external && ! this.initialization_complete)
{
OtpOutputStream polling = new OtpOutputStream();
polling.write(OtpExternal.versionTag);
polling.write_any(new OtpErlangAtom("polling"));
send(polling);
this.initialization_complete = true;
}
final int timeout_min = 10;
Integer timeout_value = null;
Long poll_timer = null;
if (timeout == null || timeout < 0)
{
// blocking on read without a timeout
}
else if (timeout >= 0)
{
poll_timer = System.nanoTime();
timeout_value = java.lang.Math.max(timeout_min, timeout);
}
try
{
ByteBuffer buffer = null;
buffer = recv(buffer, timeout_value);
if (buffer == null)
return Boolean.TRUE;
while (true)
{
int command;
switch (command = buffer.getInt())
{
case MESSAGE_INIT:
{
this.process_index = buffer.getInt();
this.process_count = buffer.getInt();
this.process_count_max = buffer.getInt();
this.process_count_min = buffer.getInt();
int prefix_size = buffer.getInt();
this.prefix = API.getString(buffer, prefix_size);
this.timeout_initialize = buffer.getInt();
this.timeout_async = buffer.getInt();
this.timeout_sync = buffer.getInt();
this.timeout_terminate = buffer.getInt();
this.priority_default = buffer.get();
this.request_timeout_adjustment =
(buffer.get() & 0xFF) != 0;
if (buffer.hasRemaining())
{
assert ! external;
handle_events(external, buffer);
}
return Boolean.FALSE;
}
case MESSAGE_SEND_ASYNC:
case MESSAGE_SEND_SYNC:
{
int name_size = buffer.getInt();
String name = API.getString(buffer, name_size);
int pattern_size = buffer.getInt();
String pattern = API.getString(buffer, pattern_size);
int request_info_size = buffer.getInt();
byte[] request_info = API.getBytes(buffer,
request_info_size);
buffer.get();
int request_size = buffer.getInt();
byte[] request = API.getBytes(buffer, request_size);
buffer.get();
int request_timeout = buffer.getInt();
byte priority = buffer.get();
byte[] trans_id = API.getBytes(buffer, 16);
int pid_size = buffer.getInt();
OtpErlangPid pid = API.getPid(buffer, pid_size);
if (buffer.hasRemaining())
{
assert external;
if (! handle_events(external, buffer))
return Boolean.FALSE;
}
callback(command, name, pattern, request_info, request,
request_timeout, priority, trans_id, pid);
break;
}
case MESSAGE_RECV_ASYNC:
case MESSAGE_RETURN_SYNC:
{
int response_info_size = buffer.getInt();
byte[] response_info = API.getBytes(buffer,
response_info_size);
buffer.get();
int response_size = buffer.getInt();
byte[] response = API.getBytes(buffer, response_size);
buffer.get();
byte[] trans_id = API.getBytes(buffer, 16);
if (buffer.hasRemaining())
{
assert ! external;
handle_events(external, buffer);
}
return new Response(response_info, response, trans_id);
}
case MESSAGE_RETURN_ASYNC:
{
byte[] trans_id = API.getBytes(buffer, 16);
if (buffer.hasRemaining())
{
assert ! external;
handle_events(external, buffer);
}
return new TransId(trans_id);
}
case MESSAGE_RETURNS_ASYNC:
{
int trans_id_count = buffer.getInt();
List<TransId> trans_ids = new ArrayList<TransId>();
for (int i = 0; i < trans_id_count; ++i)
{
byte[] trans_id = API.getBytes(buffer, 16);
trans_ids.add(new TransId(trans_id));
}
if (buffer.hasRemaining())
{
assert ! external;
handle_events(external, buffer);
}
return trans_ids;
}
case MESSAGE_SUBSCRIBE_COUNT:
{
int count = buffer.getInt();
if (buffer.hasRemaining())
{
assert ! external;
handle_events(external, buffer);
}
return count;
}
case MESSAGE_TERM:
{
if (! handle_events(external, buffer, command))
return Boolean.FALSE;
assert false;
break;
}
case MESSAGE_REINIT:
{
this.process_count = buffer.getInt();
if (buffer.hasRemaining())
continue;
break;
}
case MESSAGE_KEEPALIVE:
{
OtpOutputStream keepalive = new OtpOutputStream();
keepalive.write(OtpExternal.versionTag);
keepalive.write_any(new OtpErlangAtom("keepalive"));
send(keepalive);
if (buffer.hasRemaining())
continue;
break;
}