I/O / Streams :: How To Send Messages Efficiently From Backend To Frontend
Apr 8, 2014
I'm working on a project that has two separate components. The first is a back end, that will do most of the heavy lifting, the other part is a front end GUI. The GUI will include the back end into it's project as an imported JAR file.
I need to be able to keep these two decoupled, as I might be writing different front ends using the same back end. The challenge in front of me (well one of many) is how to pass messages from the back end to the GUI so I can report things that are happening.
For example, if i call method FOO, FOO might do several different things; connect to a database, divide by zero, solve world hunger. I want to be able to either tie a JTextArea , or another component (or multiple components) to this stack of information, or at the very least, have something listening for this information, and when I see that my back end reports something, my front end is quickly aware of this information, and then I can process it and inform the user of the front end.
It would also be useful to be able to send a message from front end to back end , so perhaps the back end might learn that the front end user is unhappy and would like to stop running the current query.
I have to write an example program to fill boxes most efficiently with bags. All bags are the same size. The boxes come in Large, Medium and Small. Large boxes hold 20 bags. Medium boxes hold 10 bags. Small boxes hold 5 bags. I am getting input from JOptionPane input dialog box and then parsing that input to an integer.
I have to fill the large and medium boxes completely. I am not sure how to do this without an if statement. I can use one, but we have not covered it in class, so I am skeptical about using one to solve the problem. If I just divide the input number with integer division, I'm not going to get the remainder, right? So I'm thinking that I can mod my input number by 20 (the number of bags the user inputs) and then mod that number by 10 and then mod that number by 5, would that work?
The goal of this software is to provide a web interface which must be able to manage the Quagga routing daemon. For those who don't know Quagga, the only interface it provides the user is its built-in cli. My project must convert web events to commands and vice-versa. how I'm going to maintain quagga's configuration state synchronized with JSF's managed beans. The example below shows the commands one must run on quagga's cli in order to add a BGP neighbor:
In order to represent this piece of information in my project, I was thinking about mapping this to a class:
public class BGPNeighbor { private String ip_address; private Integer asn; private Boolean next_hop_self; private Boolean inbound_soft_reconfiguration; }
With this I would parse the information from Quagga's configuration and map this to classes in my software. I think it's a lot easier to do with database-based software, the problem with this project is that it's not completely database oriented. The information must be fetched from the network, parsed, converted to classes and then they would be available to JSF as managed beans. Any alteration to this classes must be converted to quagga cli commands which must be executed through the network again (telnet).
We currently have an application which uses JDBC to connect to the backend database (DB version - 11.2.0.3 ). The application uses a properties file in which the password for the db schema is hardcoded in plain text format. Due to security restrictions we have been asked to make sure the password is encrypted in the file and no direct access is made to the schema using the plain text password. Best options we can use to make this password encrypted both at Oracle DB side and Java side.
I have a small problem with my code that I can't figure out how to make it work the way it is supposed to. The code is supposed to be a game where a user has to guess numbers between 1-1000. The program counts how many times the user tried to guess the number and it displays a certain message if the guess number is less than 10, more than 10 or 10. I was able to write the code using loops. However, the messages will not always get printed on to the screen. The code seems to work fine except for the last part where the messages, "Either you know the secret or you got lucky", "You should be able to do better", "Aha! you know the secret!" are not always displayed like they are supposed to.
import java.util.Scanner; public class Guess1 { public static void main(String[] args) { int secretNumber; secretNumber = (int) (Math.random() * 999 + 1); Scanner input = new Scanner(System.in); int guess; int replay; int test; test=1; replay=1; int count=0;
I have the following code that comes directly from the book Core Java vol 1. The last two statements are mine but when I change the last statement's String the message being logged doesn't change. For that manner when I change the level of the last statement the file doesn't update to the correct log level. What am I doing wrong?
Java Code:
public class LogTester { public static void main(String[] args) { if (System.getProperty("java.util.logging.config.class") == null && System.getProperty("java.util.config.file") == null)
[code]....
Forgot to say the file also only logs the old message and level from a previous recompilation
I am new to Java/OOP in general, and am trying to implement a multi-threaded system that contains a master thread, and a set of worker threads that are heterogeneous in the work they do. Once they complete the work, the workers indicate to the master by posting the result on to its queue. Here is the problem. The results of each type of work is different, and the master has to process each differently. In C (which I'm familiar with), this can be achieved by having a message type that is a union of all the expected messages, and by using a switch statement.
I thought of doing something similar in Java, by using instance of on each incoming message (each individual message class having been subclassed from a super message class) , and doing switch on that, but it doesn't seem to be the OO way to do things. The only other way I could think of was to implement an abstract method to get the type of each message, and then use the type in a switch statement, or if-then-else. Is there some other Java idiom to do this kind of processing? Also, if this is an acceptable method, why is it superior to using the reflection to find out the message type (instead of using the abstract getType())?
The message types look similar to the code below:
abstract class Message { abstract String getType(); } class Result1 extends Message { ResultType1 content; String getType() {
I am using ActiveMq alongwith Spring in my project. I want my queue to be configured to reject the duplicate messages.I tried my level best to do so. I tried googling for the same. but could not get anything.
I am having issues with a few lines of code and a java.util.UnkownFormaException. Here are the issues:
Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = '1' at java.util.Formatter.checkText(Unknown Source) at java.util.Formatter.parse(Unknown Source) at java.util.Formatter.format(Unknown Source) at java.util.Formatter.format(Unknown Source) at java.lang.String.format(Unknown Source) at Storm.toString(Storm.java:99) at StormChaser.DisplayStorms(StormChaser.java:149) at StormChaser.main(StormChaser.java:55)
I have tried a lot of different things but can't seem to figure it out.
import java.io.*; import java.util.Scanner; public class StormChaser { public static void main(String[] args)
Is there a way to inform the Entity Manager or force the JPA provider to reload data from the database? The scenario could be data being updated by a store procedure or direct SQLPlus maintenance, without restarting the Application Server, the JPA need to load the newly updated data from the database.
I think the current JPA API is not enough. The void refresh(java.lang.Object entity) from EntityManager need to pass in the Entity object, I will like to know how to refresh the entire JPA Entity data after the physical table data being update from backend.
MQ Issue on the Websphere 7.0.0.25 server ..Same Message is getting redelivered again and again and below exception is coming in System out log. And secondly the messages are not getting processed completely.
[4/7/14 12:14:58:616 GMT+05:30] 0000001e LocalTranCoor E WLTC0017E: Resources rolled back due to setRollbackOnly() being called. [4/7/14 12:16:14:738 GMT+05:30] 00000062 LocalExceptio E CNTR0020E: EJB threw an unexpected (non-declared) exception during invocation of method "onMessage" on bean "BeanId(myroj#myEJB.jar#MQMessageReceiverMDB, null)". Exception data: java.lang.reflect.InvocationTargetException at sun.reflect.GeneratedMethodAccessor77.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) at java.lang.reflect.Method.invoke(Method.java:599) at com.ibm.ejs.jms.listener.ServerSessionDispatcher.dispatch(ServerSessionDispatcher.java:47) at com.ibm.ejs.container.MDBWrapper.onMessage(MDBWrapper.java:98)
I am attempting to maintain separate files for different types of "messages" (user messages, field labels/buttons, data values). In this attempt I am trying to get the description of different data values. For example, a UserStatus "A" might be displayed as Active or Activo.
Here are the relevant entries in the values_en_us.properties file:
user.status.A = Active user.status.I = Inactive user.status.P = Pending
I would like to build an Enum for each type of value that I can get the localized value from. In the code below, I have hardcoded the values being passed to the get message to reduce the number of variables when trying to debug this.
org.springframework.context.NoSuchMessageException: No message found under code 'user.status.A' for locale 'en_us'.
On this line of code:
description = appCtx.getMessage("user.status.A", null, new Locale("en_us"));
The application is already showing my custom application error messages I have in the messages localized files, but in that case the ApplicationContext is already available. Because I can get to the contents of the messages_en_us.property files, I'm assuming me config is correct. However, the classes that get the messages content are instantiated by Spring.
The Enums are not created by Spring, so my assumption is that I am doing something wrong in how I am getting a handle on the ApplicationContext or how I am using it.
After looking at the appCtx values in debug mode, I can see that the messageSource > basenames does at least contain my configuration data.
I have some data in the database and values can be added on demand. so when ever the value added to the database i need to promt that message to all users which are accessing my website, so how can i acheive this....
I have one row editable datatable.I have implemented email validation to one of the column where error message must display on blur of email field.This is working fine.I have a dialog with form to be displayed in the same page. Validation is implemented to this form also with on blur event. The dialog validation message gets displayed on blur but along with that the main form also displays the same validation message. This should not happen.
The message with id lpcErrMsg is the one that i am displaying on blur in the main page when email format is wrong.And this message gets displayed with dialog field validation also although i have never referred to this id to be rendered in the dialog.
The message with id lpcDlgMsg is the message that i am displaying inside the dialog with widgetvar dlg on blur.As of now i have implemented blur event validation for the first required field in the dialog.
Write a class named FileDisplay with the following methods:
1.) constructor: the class's constructor should take the name of a fil as an arugment. 2.) displayHead: This method should display only the first five lines of the file's contents
Here is the following code I have made so far
import java.io.*; public class FileDisplay { private String filename; public FileDisplay(String Filename) throws IOException
[Code] ....
First, in my constructor I have taken in an argument and used that argument to open up an output file. Meanwhile, I'm trying to work n the displayhead method to print out information and to read data to. I haven't opened up my input file yet, but I'm not understand how can I read a print data to an output file. in
public void displayHead() {FileWriter file=new FileWriter(Filename)}
do I make create another instance of the filewriter class to output data?
In simple words, suppose to I want to display some messages on my output file in the displayhead function. Since I already have opened up the file in the constructor, how do I combine that in this method...
Exception in thread "main" java.lang.RuntimeException: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587; nested exception is: java.net.SocketException: Permission denied: connect at com.readAlerts.SendEmailUsingGMailSMTP.main(SendEmailUsingGMailSMTP.java:63) Caused by: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587; nested exception is:
[Code]...
Tried every permutation and combination but all leading to this same error.
I want to send a message to a specific client in a server. This is my code and what I tried(I have only given you 3 classes in which I believe I have the problem).
TextClient: import java.io.*; import java.net.*; import java.util.ArrayList; import java.util.Scanner; import java.util.concurrent.TimeUnit; public class TextClient { public TextClient() {
I have to send a request with post parameters from one web application to another web application,both are running different servers.
In my application i don't have any JSP,html only controller part which will handle request extract request parameters & based on request params i'll do a web service call.
My current requirement is based on request parameters i'll send request to another web application with received parameters.
I tried with sendRedirect() ,but it support only get() method.