Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
For example , I develop a connection pool as a server , and on the other application I want to use the connection existing in the pool , How can I get it ? they are in two processes ? and have different life circle ?
If you are talking about socket connections (i.e. your connection pool handles tcp connections), then you can't pass that connection from one process to another. However, you could have a connection from the second process to the server and relay the information to the second process (essentially acting as a proxy).
In general, you will need a way for the two processes to communicate. If they have a different lifecycle (which you hint at) and you need one process to pick up messages from the other process when it comes on line, then you will need a persistence and queuing mechanism as well. Depending on your needs there are many different ways to achieve this. Here are some examples: -
On the server, write the information to a socket and read it on the other process. You would use one of the Java messaging classes and might serialiaze the object information. This is non-persistent, but might be the easiest to begin with.
On the server, write the information to a file and signal either by a named semaphore, file or other means that there is information to be processed.
On the server, write the message to a guaranteed delivery queue (e.g. Amazon or Azure queue) so that it can be picked up by the other process when available.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I built up my server for my app which is running on Android. And i will hear some opinions from you if the setup is acceptable or complete wrong. So the architecture works like request-respone.
The user will log-in, every app start and will get a new session id.
The client and the server does not have a keep-alive connection. The connection is getting cut every request. For every command on the server, the session id need to get checked first, and then the command or request can be calculated. After everything is done the connection will cut. I was thinking about something that the connection will be held to the server and this gives me the possibility to send from the server some data directly to the client. This could have many usages. But on the other hand its not thread "able". Because i will have to synchronize the socket access and share 1 socket object between all classes and activity, this isnt in my opinion a good way. But am still wondering how other apps or online games could sent data or messages directly to the client. This means that a connection is held. I think that they doing it seperated in a service or something like this. This a new problem im facing. I could use firebase cloud messaging, but this is very slow when more as 100 threads are running on the server. A better solution where, to code a second server program, which is running seprated from the main server and keeps a connection to the client. This would be my solution.
What i just want to know if my architecture is good to go or its a bad idea.
In my opinion, opening and closing the connection is a good practice, because the connection is relatively an expensive resource.
So, I would say that yes, you're good to go with the architecture that you currently have implemented.
Open connection
Execute operation
Close connection
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a scenario where I am dealing with multiple incoming and outgoing connections. Which design pattern in java will be suitable for me to deal with such scenario.
I have multiple incoming connections like FTP, SFTP , HTTP , Database and multiple outgoing connections also FTP , SFTP , HTTP , Database. I am new to design patterns , I just want to know which design pattern best fit in my case.
I strongly recommend the Half-Sync Half-Async (http://www.cs.wustl.edu/~schmidt/PDF/PLoP-95.pdf) as a general way to deal with the complexity of having (possibly) blocking communication creating asynchronous tasks that need to be executed in order to give a result back to the caller.
It is a very general design pattern so it certainly fits several client-servers protocols you cited.
ESB, suggested in another answer is not adequate to what you are looking for, since it is based on a model in which you have several processes all connected to a message bus. All those processes exchange messages and they are all typically connected to one or more message queues or message topics. Think of it as the postal service. All houses (processes) have the same role and all of them talk with the postal service in order to exchange messages.
In your problem, you have two distinct roles: a client role and a server role. Your problem seems to be how to organize the server internally, not how to coordinate servers or equal peers.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
What i am trying to do is an app similar to teamviewer using java.I was thinking to get the Input stream (monitor's) and send it to client so that the other machine can show the screen. I learnt that kernel acts as an interface between hardware and software, and i end up asking about kernel's interaction. can u plz give me the idea so that i can get things done..
Am i doing things wrong??
Please help me out..
You can use a ScheduledExecutorService to perform an action or task after a specific delay (or at a specific time).
This is how you can trigger a thread and therefor the processor to perform instructions at a given time.
I was thinking to get the Input stream (monitor's) and send it to client so that the other machine can show the screen.
For this sort of question is it not to useful to think in terms of what the kernel is actually doing other than to not you can't pass an InputStream from one process to another, let alone one machine to another.
What you can do if establish a socket connection between the two machines and copy the InputStream into the Socket connection. At the other end you will get an InputStream which has all the data the original InputStream has.
I learnt that kernel acts as an interface between hardware and software, and i end up asking about kernel's interaction.
The kernel's role is to control and manage the TCP socket and the network adapter. The JVM interacts with the kernel for you so you don't need to know all the details, in fact you don't need to know the actual system call used which is useful as it can be different on different OSes.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have gone through resources on building chat application using socket programming in java. In every implementation people try to make a server which runs in infinite loop, accepting the connections from client and creating a separate thread for handling the chat.
I want to make a chat application in which a new dialog/chat window pops when someone wants to chat with me (on client side). But the catch is that i have only one socket through which i am connected to server. all the messages has to be sent through this streams, currently i am thinking of some adhoc approaches for directing output to different client windows but i am sure that there must be some elegant way to do this.
If you want to use a single socket connection per client, then all communication should be multiplex over that connection, which means that you need to develop a protocol on top of socket streams between your server and a client. A protocol is a set of rules. For example, clients may issue commands and server respond to them, like one command, one response. The commands and responses need to be marked and separated somehow from each other, perhaps you want to add an identifier and a length of a message and then refer to that message.
Various systems use different protocols.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
we are planning to design a system where data comes through web services and data will be processed asynchronously, i have been assigned to pick java open source technologies to do this, for web services we have decided to go with Restful services, I never worked with messaging technologies , can anyone please suggest which is the best open source technology that is available in the market that does data process asynchronously
Try Apache CXF - see the DOCS
It has everything you want i guess
Your use case is of processing of data asynchronously. This typically happens in following steps:
Receive the data and store it somewhere (in-memory or persistent location)
Return the Acknowledged/Received response immediately.
Either immediately start a thread to process the data or let some scheduled thread scan the received data and process it.
Optionally sent acknowledge to the sending application if such an interface is available.
There is no standard library or framework in java to do this. There are individual pieces which are know to solve standard problems and combining them will be one options.
Producer consumer Pattern is a typical patter which satisfies your need over there.
You can build a producer-consumer pattern using Java's concurrent APIs (Here is an example)
This producer consumer piece can be wrapped behind a Servlet (Or some other server side class which handles requests).
All in incoming request will put by the producer on the shared queue and return.
Consumer will pick it from the queue and process it asynchronously.
Another option would be to use Asynchronous processing in in Servlet3.0.