Hi Trustin
Thanks for your answers alwayd in detail. Congralution to your marriage.
Are you in Korea now? Actually I have some business parnters IT guys living
in seoul and i visited there last year. Please see * for my question below.
Mat
2007/4/19, Trustin Lee <[EMAIL PROTECTED]>:
Hi mat,
On 4/19/07, mat <[EMAIL PROTECTED]> wrote:
> Dear all,
>
> I am using mina as both server and client in my service. I just wonder
if I
> should use IO/service(process) threads provided by mina to handle the
> business logic?
> what I understood is:
> I added config.getFilterChain().addLast("threadPool", new
ExecutorFilter(
> Executors.newCachedThreadPool())) at server.
There's no direct relationship between implementing business logic and
adding an executor filter to the filter chain. You can execute the
business logic in your IoHandler even if you didn't add an executor
filter. An executor filter is required only the the business logic
performs a blocking operation such as database access.
Probably most business logic will involve external resources like
database, you are likely to add an executor filter.
> 1) If client connector also needs config.getFilterChain
().addLast("threadPool",
> new ExecutorFilter(Executors.newCachedThreadPool())) ? If so, how to
control
> the numbers of threads for both servers and clients in order to reach
the
> maxiuam performance. I have 4, 5 client connections.
If you want to control the maximum number of threads, you will have to
create a different Executor that just
'Executors.newCachedThreadPool()'. You need to consult the JavaDoc of
java.util.concurrent.Executors class.
MINA executor filter ensures only one event is processed per session,
so you will have 5 active thread at max even if you used
Executors.newCachedThreadPool().
Again, creating an executor is what MINA does but you do. Please
check the Java SE API documentation.
* In your tutorial, you suggested number of processor + 1 thread. However,
my applicaiton has 1 server and 5, 6 clients in one process. If my server
acceptor follows this rule, how about my client connectos?
* In the tutorial, Executors.newCachedThreadPool() is always preferred
by IoService?
I am confused.
2) Since in my application, the data is big. What if mina IO/Process CAN'T
handle them in time? Put them in the mina internal queue? Or drop them? I
really worry about the memory problem.
If the data is too big to load the whole data into the heap, things
become tricky. People usually split the big data into multiple
messages.
* when I said 'big', i meant 'fast' and huge data.
3) If i use IO/process threads, the messageReceived methods will be called
> asychronized. Am I right? If so, how can I make sure the incoming events
is
> processed in order?
I don't get your question here. MINA can't do anything without I/O
processor threads.
* We didn't add any ExecutorFilter so far. If no ExecutorFilter is added,
events are forwarded to an IoHandler via method invocations. This means your
business logic in your IoHandler
* implementation will run in the I/O processor thread. We call this thread
model a '*single thread model*'. (from tutorial)
* Actually i am making a Gateway bypassing the message, the job of Gateway
one side(client connectors 5, 6) is decoding or encoding messages, the
other side is server which handles end clients.
* So I don't need to add an ExecutorFilter, do I?
Anyway, the order of events is always maintained correctly. You don't
need to worry one message arrives before the other arrives.
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6