I am using wakefull intent service and works very fine. But currently i see that many times my intent service is in wait satate.I found that problem is with javamail as it goes in deadlock state when ever internet connection is resets.
I search option to intrupt operation java mail but can't find any solution.I have set IMAP,SMTP Time out property but it is not working.
if(msg1[0]!= null)
{
if(!Mail.store.isConnected() || f== null)
{
Log.v(tag, "StoreNot Connected");
m = new Mail(username, password);
f =m.getlable("Message_"+nick);
Log.v(tag, "Store Connected");
}
try{
Log.v(tag, "Sending Mail");
//Get DeadLock Hear
f.appendMessages(msg1);
sucess_flag=1;
Log.v(tag, "Mail Send");
}
catch(Exception e)
{
e.printStackTrace();
}catch(Throwable e)
{
e.printStackTrace();
}
}
So now i am looking for an option to restart or kill the current intent service.
Is there any option for this?
If not then is it a good idea to create theads from intentservice and kill them instead?
Try this:
Intent GPSService = new Intent(context, TrackGPS.class);
context.stopService(GPSService);
Related
I'm using Javamail with an implementation of MessageCountListener to read incoming emails on an Exchange 2010 server, using IMAP over an SSL connection.
We are currently testing the app.
Most days, the app processes the incoming emails and extracts their attachment files and then marks the emails as 'read':
try {
email.setFlag(Flag.ANSWERED, true);
email.setFlag(Flag.SEEN, true);
} catch (final MessagingException e) {
log.warn("Can't set msg to read - fail transaction...", ex);
// etc
}
But on some days, this doesn't work. I can see in the Outlook inbox folder that approximately 30% of the emails are left 'unread'. However there is no exception logged and the app otherwise works perfectly, so it seems.
This of course leads to problems since the app will re-process the emails and their file attachments when it is re-started, since it sees them as unread.
This is only on our test server and I haven't been able to reproduce it on my local dev box.
Can anyone advise how to approach this problem or say if they have seen it too?
My MessageCountListener implementation:
#Override
public void messagesAdded(final MessageCountEvent event) {
Message[] newEmails = event.getMessages();
if (newEmails != null) {
log.debug(String.format("%d message(s) added", newEmails.length));
for (Message email : newEmails) {
Folder folder = email.getFolder();
Store store = folder.getStore();
statusOK = processor.runTransaction(email);
if (statusOK) {
messageCount++;
} else {
log.trace("shutting down listener due to error");
store.removeConnectionListener((ConnectionListener) this);
break;
}
}
} else {
log.debug("Added null new emails array");
}
}
Hi Im new at Silverlight/async programming
Situation: Silverlight app as a webresource that make CRUD operations
Problem: The entity have a plugin step registered to it as Synchronous. Then in silverlight when the code execute the EndSaveChages(results) method I get a SystemException.
The message received is:
The current object did not originate the async result.Parameter name:
asyncResult
I tried using a lock, Thread.Sleep, While and the Dispatcher but nothing help. There is a way to hold the process until I receive the asycResult?
Code:
private void OnUpdateRecordComplete (IAsyncResult result)
{
try
{
while (!result.IsCompleted)
{
}
Thread.Sleep(1000);
xrmsm_scores updatedRecord = result.AsyncState as xrmsm_scores;
context.EndSaveChanges(result);
// MessageBox.Show("Save Completed!");
MessageBox.Show(updatedRecord.xrmsm_studentsName.Trim() + "'s Grade has been updated!");
//MessageBox.Show("HUGE SUCCESS!");
}
catch (DataServiceRequestException se)
{
MessageBox.Show("The score information could not be saved.\nReason: " + getXMLError(se), "Error!", MessageBoxButton.OK);
studentName = string.Empty;
}
catch (SystemException se)
{
isSaved = true;
//string error = se.Message.Replace('"', '\'').Replace("\r\n", #"\n");
//MessageBox.Show("OnUpdateRecordComplete SystemExeption Catch: " + error);
//It always goes on catch because we are not using MVC System
//It saves it anyways :P
//MessageBox.Show("OnCreateRecordComplete");
//syncContext.Send(new SendOrPostCallback(showErrorDetails), se);
}
}
You shouldn't have to do sleeping or waiting. My understanding is that the complete event handler is only called once async call returns.
Have you seen this sample? It should help to guide you in the right direction.
Sample: Create, Retrieve, Update and Delete Using the REST Endpoint with Silverlight
I created application that runs on GAE and connects to specific page, automatically logins to this page and AFTER login I want to receive html and process it.
here is the problematic (writer.write part and connection.connect()) part of code:
this.username = URLEncoder.encode(username, "UTF-8");
this.password = URLEncoder.encode(password, "UTF-8");
this.login = "login";
connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
OutputStreamWriter writer = new OutputStreamWriter(
connection.getOutputStream());
writer.write("str_login=" + login + "&str_user=" + username
+ "&str_pass=" + password);
writer.close();
connection.connect();
I am getting IOException (connection.connect()) while establishig connection. Problem is "application/x-www-form-urlencoded" data. When I pass wrong parameters to page (for example str_pasSSs, str_usernaAAme, or no parameters at all) I am not possible to login but I do get response with html of login page. So, it seems that Google App Engine does not support this kind of communication. Is it possible to login to this page in some other way that GAE supports?
In Wireshark, I saw that username and password are sent in plaintext as line-based text data (application/x-www-form-urlencoded). I know this is not safe, but it's the way it is.
The connection is already established implicitly when you call getOutputStream(). There is no need to call connection.connect() again.
Also, instead of closing the output writer, try flush() instead.
As a best practice, you should be closing in, out and conn in a finally block:
InputStream in = null;
OutputStream out = null;
HttpUrlConnection conn = null;
try {
...
} catch (IOException ioe) {
...
} finally {
if (in!=null) {try {in.close()} catch (IOException e) {}}
if (out!=null) {try {out.close()} catch (IOException e) {}}
if (conn!=null) {try {conn.close()} catch (IOException e) {}}
}
I was originally coding on a server with Apache installed and used this function to connect to the database
public Connection getDBConnection()
{
java.sql.Connection conn=null;
//synchrnized(this)
try
{
DriverManager.registerDriver(new OracleDriver());
conn = DriverManager.getConnection("jdbc:oracle:thin:#dukeorrac01:1521:ORDB1","nrsc","nrsc");
}
catch (Exception e)
{
e.printStackTrace();
}
return conn;
}
Probably not the best way to do it, but it worked. However, I've moved to coding on my local machine and I was given jboss as an IDE to work with. I've gotten everything working (sorta) except, it seems to be connecting to a different databse. I get exhausted resultsets (which isn't right). I "thought" the "getConnection("jdbc:oracle....") was what established the connection to the actual database.
Why is this not working on my local machine when it worked perfectly fine on the remote server?
P.S. I'm new to database/server configuration stuff. So, don't assume I know some step in setting up a database or server. Also, I did not create this orginally. It was given to me to use.
Thanks
The error seems to indicate that you are not closing your result sets properly. In the following example see how after a statement is executed you have to close those resources in the finally block.
W.r.t why you did not see this error before is probably because your server probably had lots of resources whereas your local machine has limited resources and your default settings are not modified to reflect the needs of your application.
In general, its better to do basic house keeping like closing all the open result sets and statements whether or not you have enough resources allocated on your DB.
public void getDBConnection() {
Connection conn = null;
Statement statement = null;
ResultSet rs = null;
try {
connection = DriverManager.getConnection("jdbc:oracle:thin:#dukeorrac01:1521:ORDB1","nrsc","nrsc");
statment = connection.createStatement();
statement.setFetchSize(Integer.MIN_VALUE);
// Do more stuff, iterate to ResultSet etc...
} catch (SQLException ex) {
// Exception handling stuff
...
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) { /* ignored */}
}
if (statment != null) {
try {
statment.close();
} catch (SQLException e) { /* ignored */}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) { /* ignored */}
}
}
}
I'm using the MailService feature of Google App Engine in my
application. It works fine in one application without any issues.
But the same code doesn't work in another app. I'm not able to figure
it out. Please help. Following is the piece of code that I use to
send mail.
public static void sendHTMLEmail(String from, String fromName, String
to, String toName, String subject, String body) {
_logger.info("entering ...");
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
_logger.info("got mail session ...");
String htmlBody = body;
try {
Message msg = new MimeMessage(session);
_logger.info("created mimemessage ...");
msg.setFrom(new InternetAddress(from,
fromName));
_logger.info("from is set ...");
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(
to, toName));
_logger.info("recipient is set ...");
msg.setSubject(subject);
_logger.info("subject is set ...");
Multipart mp = new MimeMultipart();
MimeBodyPart htmlPart = new MimeBodyPart();
htmlPart.setContent(htmlBody, "text/html");
mp.addBodyPart(htmlPart);
_logger.info("body part added ...");
msg.setContent(mp);
_logger.info("content is set ...");
Transport.send(msg);
_logger.info("email sent successfully.");
} catch (AddressException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.getMessage());
}
}
When I look at the log (on the server admin console), it prints the
statement "content is set ..." and after that there is nothing in the
log. The mail is not sent. At times I get the following error after
the above statement is printed (and the mail is not sent).
com.google.appengine.repackaged.com.google.common.base.internal.Finalizer
getInheritableThreadLocalsField: Couldn't access
Thread.inheritableThreadLocals. Reference finalizer threads will
inherit thread local values.
But the mail quota usage keeps increasing.
Remember, this works fine in one application, but not in other. I'm
using the same set of email addresses in both the apps (for from and
to).
I'm really stuck with this. Appreciate any help.
Thank you.
Velu
Have you tried logging the exceptions? I bet one of them is being thrown - your printStackTrace will go nowhere.