Frontend Instance Hours - How can I decrease the usage? - java

I'm trying to use the free Google App Engine as a backend for Google Cloud Messages for my next Android app but when I have "finished" writing the server it already uses almost 100% of the free frontend instance hours. The question I have is if and how I can improve this?
The application is a servlet that is called every 15 minutes from a cron job, the servlet downloads and parses 3 RSS feeds and checks if anything has changed since the last call, saves the dates to the database (JDO and memcache, 3 calls) to know when the last running was and if any changes have happend since the last call sends that information out the the connected phones, right now 3 phones are connected, it's just one call to Googles servers. No data is returned from the servlet.
Here is the code
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException
{
boolean sendMessage = false;
String eventsFeedUrl = "http://rss.com";
String newsFeedUrl = "http://rss2.com";
String trafficFeedUrl = "http://rss3.com";
response.setContentType("text/plain");
Message.Builder messageBuilder = new Message.Builder();
String messageData = getFeedMessageData(eventsFeedUrl);
if (!messageData.equals(StringUtils.EMPTY))
{
messageBuilder.addData("event", messageData);
sendMessage = true;
}
messageData = getFeedMessageData(newsFeedUrl);
if (!messageData.equals(StringUtils.EMPTY))
{
messageBuilder.addData("news", messageData);
sendMessage = true;
}
messageData = getFeedMessageData(trafficFeedUrl);
if (!messageData.equals(StringUtils.EMPTY))
{
messageBuilder.addData("traffic", messageData);
sendMessage = true;
}
if (sendMessage)
{
sendMessage(messageBuilder.build(), response, debug);
}
}
private void sendMessage(Message message, HttpServletResponse response, boolean debug)
throws IOException
{
SendResult sendResult = GCMService.send(message, Device.list());
int deleteCount = 0;
for (MessageResult errorResult : sendResult.getErrorResults())
{
if (deleteCount < 200 && (errorResult.getErrorName().equals(Constants.ERROR_NOT_REGISTERED) || errorResult.getErrorName().equals(Constants.ERROR_INVALID_REGISTRATION)))
{
Device.delete(errorResult.getDeviceId());
deleteCount++;
}
}
}
private String getFeedMessageData(String feedUrl)
{
String messageData = StringUtils.EMPTY;
FeedHistory history = FeedHistory.getFeedHistoryItem(feedUrl);
Feed feedContent = RssParser.parse(feedUrl);
if (feedContent != null && feedContent.getFeedItems().size() > 0)
{
if (history == null)
{
history = new FeedHistory(feedUrl);
history.setLastDate(new Date(0));
history.save();
}
for (FeedItem item : feedContent.getFeedItems())
{
if (item.getDate().after(history.getLastDate()))
{
messageData += "|" + item.getCountyId();
}
}
if (!messageData.equals(StringUtils.EMPTY))
{
messageData = new SimpleDateFormat("yyyyMMddHHmmssZ").format(history.getLastDate()) + messageData;
}
history.setLastDate(feedContent.getFeedItem(0).getDate());
history.save();
}
return messageData;
}
The call Device.list() uses memcache so after one call it will be cached, the RSS parser is a simple parser that uses org.w3c.dom.NodeList and javax.xml.parsers.DocumentBuilder. According to the log file I use the same instance for days so there are no problems with instances starting up and taking resources. A normal call to the servlet looks like this in the log,
ms=1480 cpu_ms=653 api_cpu_ms=0 cpm_usd=0.019673
I have some ideas of what to try next, try to do the RSS download calls async to minimize the request time. Move the RSS parsing to a backgroud job. What else can be done? It feels like I have done some fundamental errors with my code here because how can a normal web app work if this servlet can't be called 100 times during 24 hours without consuming 100% of the frontend hours.
/Viktor

Your idle instances hang around for a little while before shutting themselves down. I don't know how long this is, but I'm guessing it's somewhere in the 5-15 minute range. If it is in fact 15 minutes, then your cron job hitting it every 15 minutes will keep it alive indefinitely, so you'll end up using 24 instance hours a day.
You can test this theory by setting your cron job to run every 30 minutes, and see if it halves your instance hour usage.

Related

Getting "Task is not yet complete error" when reading data using google fit android api

I am learning Android, and my task is to retrieve steps data using Google Fit steps API. However, I keep getting "Task is not yet complete" error. I am not sure
This is my code for that part:
private List<Fitness> readHistoryDataFromGoogle() {
DataReadRequest readRequest = createDataReadRequest();
Task<DataReadResponse> response = com.google.android.gms.fitness.Fitness.getHistoryClient(this, GoogleSignIn.getLastSignedInAccount(this)).readData(readRequest);
DataReadResponse responses = response.getResult();
List <Fitness> fitnessItems = parseFitness(responses);
return fitnessItems;
}
private List<Fitness> parseFitness(DataReadResponse dataReadResponse) {
List<com.example.mentalhealthapp.Fitness> fitnessItems = new ArrayList<>();
for (Bucket bucket : dataReadResponse.getBuckets()) {
for (DataSet set : bucket.getDataSets()) {
for (DataPoint dataPoint : set.getDataPoints()) {
int numSteps = dataPoint.getValue(Field.FIELD_STEPS).asInt();
long startDateTime = dataPoint.getStartTime(TimeUnit.MILLISECONDS);
long endDateTime = dataPoint.getEndTime(TimeUnit.MILLISECONDS);
fitnessItems.add(new com.example.mentalhealthapp.Fitness(numSteps, startDateTime, endDateTime));
}
}
}
return fitnessItems;
}
Thank you very much for your help!
You're getting this problem, because API requests (service calls) are Asynchronous, they don't complete and return data immediately and you can't run them line by line like other code. you have to WAIT for that response to complete before you can access the data it returns.
from the documentation it tells you it's a REST api:
Brief look at documentation
https://developers.google.com/android/reference/com/google/android/gms/fitness/RecordingClient suggests you should look at this for displaying data when it becomes available.

Direct messaging communication failure over BLE between Android and Garmin FR230 (SDK 1.3.x)

Hi fellow Garmin developers,
I have been trying to develop a direct messaging communication setup over BLE between my Android App and my connectIQ app (on Garmin Forerunner 230, SDK version 1.3.x). The goal here is that the Android app is collecting some data, and then pushing it to the watch app.
Following the details on the developer site, I have managed to get this to work, but there are a lot of dropped messages that don't get sent, and the watch receives fewer values than what is being sent.
On Android, I get this status (ConnectIQ.IQMessageStatus) = FAILURE_DURING_TRANSFER in my debug statements. '240' is the data being sent.
D/GarminMessenger: onMessageStatus: Message: 240, device: Forerunner 230, FAILURE_DURING_TRANSFER
This is my app code on the garmin:
SampleApp.mc
using Toybox.Application as App;
using Toybox.Communications as Comm;
using Toybox.WatchUi as Ui;
using Toybox.System as Sys;
var mailMethod;
var crashOnMessage = false;
var msg;
class SampleApp extends App.AppBase {
function initialize() {
AppBase.initialize();
Sys.println("app-initialize()");
msg = "0";
mailMethod = method(:onMail);
Comm.setMailboxListener(mailMethod);
Sys.println("app-initialize(): mail box listener has been set");
}
// onStart() is called on application start up
function onStart(state) {
System.println("app-onStart()");
}
// Return the initial view of your application here
function getInitialView() {
Sys.println("app-getInitialView()");
return [ new SampleAppView() ];
}
function onMail(mailIter) {
var mail = mailIter.next();
while(mail!=null) {
Sys.println("app-onMail: received - "+mail);
message = mail.toString();
Ui.requestUpdate();
mail = mailIter.next();
}
Comm.emptyMailbox();
}
// onStop() is called when your application is exiting
function onStop(state) {
System.println("app-onStop()");
}
}
class CommListener extends Comm.ConnectionListener {
function initialize() {
Comm.ConnectionListener.initialize();
sys.println("commlistener-initialize");
}
function onComplete() {
Sys.println("commlistener-onComplete: Transmit Complete");
}
function onError() {
Sys.println("commlistener-onError: Transmit Failed");
}
}
Any ideas on what could be causing this issue? I am performing all the necessary checks on the Android side to verify if the Garmin watch is paired and connected (&the app is open).
One reason this could be happening is that I am trying to send 1-2 data values (each with a ConnectIQ.sendMessage()) every second, so perhaps the Garmin device/BLE module does not support communication at that rate?
Thanks in advance for solutions and suggestions.
I think that the Connect messaging system just gets into some broken state and then no messages will go through.
What you could try is to set up the Mailbox listener in onStart method instead of initialize.
Also there is a new method to make the message reading a lot easier. It is still largely undocumented, but I got a word it will be documented with the next SDK release. However, it is already working on every ConnectIQ watch.
The method is:
Comm.registerForPhoneAppMessages(method(:onMsg));
where in your callback method you do:
function onMsg(msg) {
handleIncomingMessage(msg.data.toString());
}
or something similar. The input object msg is of class
Toybox::Communications::Message
probably (this is not documented yet).
So I posted a similar question on the Garmin developer forum here, and got a partial answer to my problem. Posting a summary from there.
What I was hoping to implement was something life the following:
Assuming the messages from Android are 1, 2, 3, 4, 5: I would like the
app to do update the UI as the messages are received, in real-time like this:
app-onMail: received - 1
//update the UI
app-onMail: received - 2
//update the UI
app-onMail: received - 3
//update the UI
app-onMail: received - 4
//update the UI
app-onMail: received - 5
//update the UI
Instead, this happens
app-onMail: received - 1
app-onMail: received - 2
app-onMail: received - 3
app-onMail: received - 4
app-onMail: received - 5
//update the UI
//update the UI
//update the UI
//update the UI
//update the UI
THE ANSWER
The framework polls to see if there are new, unread mail messages. If there are any, it invokes the application onMail() callback which consumes each message from the queue, and repeatedly sets a flag that indicates the UI needs to update. After the call returns, the framework checks the flag to see if the UI needs to be updated, and if so it calls onUpdate() for the active view.
As such, I could only display every message if I send messages from Android at 5sec intervals. I could not find a way to receive and display data at higher rates due to its message polling frequency.
My responder suggested maintaining a queue of mail items (or just a counter) and then handling the mail items between draws, like this:
class MyApp extends App.AppBase
{
hidden var _M_messages;
hidden var _M_count;
function initialize() {
AppBase.initialize();
_M_messages = new [10];
_M_count = 0;
}
function getInitialView() {
return [ new MyView() ];
}
function onStart(params) {
Comm.setMailboxListener(self.method(:onMail));
}
function onStop(params) {
Comm.setMailboxListener(null);
}
function onMail(mailIter) {
var mail = mailIter.next();
while (mail != null) {
// only track up to 10 messages
if (_M_count < 10) {
_M_messages[_M_count] = mail;
++_M_count;
}
else {
break;
}
mail = mailIter.next();
}
Comm.emptyMailbox();
startProcessingMessages();
}
hidden function startProcessingMessages() {
if (_M_timer == null) {
_M_timer = new Timer.Timer();
_M_timer.start(self.method(:processOneMessage), 250, true);
}
}
hidden function stopProcessingMessages() {
if (_M_timer != null) {
_M_timer.stop();
_M_timer = null;
}
}
function getMessageCount() {
return _M_messages;
}
function processOneMessage() {
if (_M_count != 0) {
--_M_count;
var mail = _M_messages[_M_count];
_M_messages[_M_count] = null;
// process the message here
Ui.requestUpdate();
if (_M_count == 0) {
stopProcessingMessages();
}
}
}
}
class MyView extends Ui.View
{
hidden var _M_app;
function initialize(app) {
View.initialize();
_M_app = app;
}
function onUpdate(dc) {
var mailMessages = _M_app.getMessageCount();
// draw the number of mail messages
}
}

Robovm Local notifications not showing up. Scheduling seems successful. Am I missing something?

I am trying to get local/scheduled notifications working. With push messages (using Parse) working fine I though local would be easy, but even though the registration seems to go fine (didRegisterUserNotificationSettings is fired) and the scheduling seems to work too, the notification does not show up. I have tested on iOS 7 (iphone 4) and iOS 9 (iphone simulator). What am I missing?
here is my code:
#Override
public boolean didFinishLaunching(UIApplication application,UIApplicationLaunchOptions launchOptions)
{
boolean retval = super.didFinishLaunching(application, launchOptions);
//some other stuff happens here regarding parse push. But since this works I have cut it out
registerForPush();
return retval;
}
public void registerForPush()
{
if (IOSLauncher.getOSMajorVersion() >= 8)
{
UIUserNotificationType userNotificationTypes = UIUserNotificationType.with(UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound);
UIUserNotificationSettings settings = new UIUserNotificationSettings(userNotificationTypes, null);
application.registerUserNotificationSettings(settings);
application.registerForRemoteNotifications();
}
else
{
UIRemoteNotificationType type = UIRemoteNotificationType.with(UIRemoteNotificationType.Alert, UIRemoteNotificationType.Badge, UIRemoteNotificationType.Sound);
application.registerForRemoteNotificationTypes(type);
}
}
public void scheduleNotification(String title, String text, Date date, int ID)
{
UILocalNotification notification = new UILocalNotification();
if(getOSMajorVersion() >= 8 && getOSMinorVersion() >= 2)
notification.setAlertTitle(title);
notification.setAlertBody(text);
notification.setFireDate(new NSDate(date));
NSMutableDictionary<NSObject, NSObject> dict = new NSMutableDictionary<>();
dict.put("id",NSNumber.valueOf(ID));
notification.setUserInfo(dict);
UIApplication.getSharedApplication().scheduleLocalNotification(notification);
}
Edit:
After settting the notification it is present in the array returned by:
UIApplication.getSharedApplication.getScheduledLocalNotifications();
The problem was resolved after Adding:
notification.setTimeZone(NSTimeZone.getLocalTimeZone());
and setting the expire time of my test timer from 1 minute to 5 minutes
I'm not sure which is the actual solution, but the problem is gone, so I'm happy!
EDIT:
UILocalNotification notification = new UILocalNotification();
notification.setAlertTitle("title");
notification.setAlertBody("text");
NSMutableDictionary<NSObject, NSObject> dict = new NSMutableDictionary<>();
//add any customer stuff to your dictionary here
notification.setUserInfo(dict);
notification.setFireDate(new NSDate(date)); //date is some date in the future. Make sure it is in the correct TZ. If it does not work, try to make it at least 5 minutes in the future. I remember this helping my situation
notification.setTimeZone(NSTimeZone.getLocalTimeZone());
UIApplication.getSharedApplication().scheduleLocalNotification(notification);

Prevent continuous F5 on a web application

This is related with handling the scenario when some crazy user is holding down the F5 key to send unlimited requests to our server.
Our application is very much database and cache intensive and when such consecutive requests come in; our web application is crashing after some time. I know we need to fix the application cache handling and need to add some check at the web server but I am asked to take care of this issue in our code.
I am handling this on both Javascript and server side, but looks like still it is failing, so would like to know if you have any better solution.
My code is as follows:
Javascript Code:
function checkPageRefresh(e) {
e = e || window.event;
ar isPageRefreshed = false;
// detect if user tries to refresh
if ((e.keyCode == 116) /* F5 */ ||
(e.ctrlKey && (e.keyCode == 116)) /* Ctrl-F5 */ ||
(e.ctrlKey && (e.keyCode == 82)) /* Ctrl-R */) {
isPageRefreshed = true;
}
// only trigger special handling for page refresh
if (isPageRefreshed){
var lastRefreshTimeMillis= readCookie("last_refresh");
var currentTimeMillis = new Date().getTime();
// set cookie with now as last refresh time
createCookie(lastRefreshCookieName, currentTimeMillis);
var lastRefreshParsed = parseFloat(lastRefreshTimeMillis, 10);
var timeDiff = currentTimeMillis - lastRefreshParsed;
var F5RefreshTimeLimitMillis = <%=request.getAttribute("F5RefreshTimeLimitMillis")%>;
// if detected last refresh was within 1 second, abort refresh
if (timeDiff < F5RefreshTimeLimitMillis) {
if (e.preventDefault) {
e.preventDefault();
return;
}
}
} // end if (isPageRefreshed)
}
Java Code:
Queue<VisitsInfoHolder> recentlyVisitedUrls = (LinkedList<VisitsInfoHolder>)session.getAttribute(SupportWebKeys.RECENTLY_VISITED_URLS);
String urlBeingCalled = PageUrlUtils.getFullURL(request);
int maxCountOfRecentURLs = 3;
if(null != recentlyVisitedUrls){
//verify if last visit count is matching with the count provided
if(recentlyVisitedUrls.size() >= maxCountOfRecentURLs ) {
int noOfMatchingVisits = 0;
Long firstAccessedTime = 0l;
int count = 0;
for(VisitsInfoHolder urlIno : recentlyVisitedUrls) {
//Store the time stamp of the first record
if(count == 0 && null != urlIno) {
firstAccessedTime = urlIno.getTimeOfTheVisit();
}
count++;
//count how many visits to the current page
if(null != urlIno && null != urlIno.getUrl() && urlIno.getUrl().equalsIgnoreCase(urlBeingCalled)) {
noOfMatchingVisits++;
}
}
if (noOfMatchingVisits >= maxCountOfRecentURLs && (new Date().getTime() - firstAccessedTime) <= 1000){
LOGGER.error(">>>>> Redirecting the client to the warning page.");
VisitsInfoHolder currentVisitInfo = new VisitsInfoHolder(urlBeingCalled,new Date().getTime());
recentlyVisitedUrls.remove();
recentlyVisitedUrls.add(currentVisitInfo);
response.sendRedirect((String)request.getAttribute("F5IssueRedirectPage"));
LOGGER.error(">>>>> Redirected successfully.");
return;
}
else{
VisitsInfoHolder currentVisitInfo = new VisitsInfoHolder(urlBeingCalled,new Date().getTime());
recentlyVisitedUrls.remove();
recentlyVisitedUrls.add(currentVisitInfo);
session.setAttribute(SupportWebKeys.RECENTLY_VISITED_URLS, recentlyVisitedUrls);
}
}
else if (recentlyVisitedUrls.size() < maxCountOfRecentURLs) {
VisitsInfoHolder currentVisitInfo = new VisitsInfoHolder(urlBeingCalled,new Date().getTime());
recentlyVisitedUrls.add(currentVisitInfo);
session.setAttribute(SupportWebKeys.RECENTLY_VISITED_URLS, recentlyVisitedUrls);
}
}
else{
recentlyVisitedUrls = new LinkedList<VisitsInfoHolder>();
VisitsInfoHolder currentVisitInfo = new VisitsInfoHolder(urlBeingCalled,new Date().getTime());
recentlyVisitedUrls.add(currentVisitInfo);
session.setAttribute(SupportWebKeys.RECENTLY_VISITED_URLS, recentlyVisitedUrls);
}
Now I keep holding the F5 button then my Javascript is not understanding that the same key is held for longer time and server side code prints the following 2 loggers
Redirecting the client to the warning page.
Redirected successfully.
But in reality it is not redirecting any single time. I tried adding Thread.sleep(1000) before and after redirect, but still no luck.
Please let me know if you see any issue with my code or let me know if there is any better solution.
When you reproduce this problem are you the only person on your server? Can you reproduce this problem on your local dev instance? If so you really need to fix your server code such that it doesn't crash. You are doing something on your server that is too intensive and needs to be optimized.
Simply intercepting the F5 key on someone's browser is treating the symptoms not the disease. If you are having problems handling a single user hitting F5 really quickly it simply means you'll never be able to scale up to many simultaneous users because that's the exact same request/response pattern as a single user round tripping you with F5.
It's time to break out the profiler and check the timings on how long it takes to process a single request through the system. Then look for hotspots and optimize it. Also watch your memory usage see if you are cleaning things up or if they are growing off into infinity.

YouTube API too_long error code on short keywords?

I feel really silly to not be able to find this answer anywhere. Could someone please direct me to a place or inform me of what the YouTube limits are with regard to keywords?
I found that the limit was once 120 characters, but then I heard it changed in March 2010 to 500 characters so it shouldn't be a problem for me if that's true. It's possible I have another problem on my hands. Maybe someone could help me with that one...
I'm using the YouTube API for Java using direct upload from a client based application. I have tons of videos I'm trying to upload to several different accounts at once (each in a different language). So I'm using threads to accomplish this. I limit the number of concurrent uploads to 10 just to try and play it safe. None of the descriptions will be much longer than 500 characters and because of this error I'm getting, I had the keywords automatically limit themselves to 120 characters (I even tried to limit it to 70 characters and had the same problem). So, I'm not sure at all why this is happening. The error I get from Google is:
SEVERE: null
com.google.gdata.util.InvalidEntryException: Bad Request
<?xml version='1.0' encoding='UTF-8'?>
<errors>
<error>
<domain>yt:validation</domain>
<code>too_long</code>
<location type='xpath'>media:group/media:keywords/text()</location>
</error>
</errors>
I'm also getting an InvalidEntryException as an error code, but I'll deal with that later (I think it has to do with my authentication timing out or something).
Anyway, I don't get this error on every video. In fact, most videos make it just fine. I haven't yet tested to find out which videos are throwing the error (I will do that when I'm finished with this post), but it's beyond me why I'm getting this error. I'll post my code here, but it's pretty much exactly what's on the api documentation, so I don't know whether it'll be much help. I'm guessing there's something fundamental I'm missing.
uploadToYouTube():
private void uploadToYouTube() throws IOException, ServiceException {
TalkContent talkContent = transfer.getTalkContent();
YouTubeService youTubeService = talkContent.getLanguage().getYouTubeService(); //see code for this below...
String title = talkContent.getTitle();
String category = talkContent.getCategory();
String description = talkContent.getDescription();
List<String> tags = talkContent.getTags();
boolean privateVid = true;
VideoEntry newEntry = new VideoEntry();
YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup();
//Title
mg.setTitle(new MediaTitle());
mg.getTitle().setPlainTextContent(title);
//Description
mg.setDescription(new MediaDescription());
mg.getDescription().setPlainTextContent(description);
//Categories and developer tags
mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, category));
mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "kentcdodds"));
mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "moregoodfoundation"));
//Keywords
mg.setKeywords(new MediaKeywords());
int tagLimit = 70; // characters
int totalTags = 0; //characters
for (String tag : tags) {
if ((totalTags + tag.length()) < tagLimit) {
mg.getKeywords().addKeyword(tag);
totalTags += tag.length();
}
}
//Visible status
mg.setPrivate(privateVid);
//GEO coordinantes
newEntry.setGeoCoordinates(new GeoRssWhere(40.772555, -111.892480));
MediaFileSource ms = new MediaFileSource(new File(transfer.getOutputFile()), transfer.getYouTubeFileType());
newEntry.setMediaSource(ms);
String uploadUrl = "http://uploads.gdata.youtube.com/feeds/api/users/default/uploads";
VideoEntry createdEntry = youTubeService.insert(new URL(uploadUrl), newEntry);
status = Transfer.FINISHEDUP;
}
getYouTubeService():
public YouTubeService getYouTubeService() {
if (youTubeService == null) {
try {
authenticateYouTube();
} catch (AuthenticationException ex) {
JOptionPane.showMessageDialog(null, "There was an authentication error!" + StaticClass.newline + ex, "Authentication Error", JOptionPane.ERROR_MESSAGE);
Logger.getLogger(Language.class.getName()).log(Level.SEVERE, null, ex);
}
}
return youTubeService;
}
authenticateYouTube():
public void authenticateYouTube() throws AuthenticationException {
if (youTubeService == null) {
System.out.println("Authenticating YouTube Service");
youTubeService = new YouTubeService("THENAMEOFMYPROGRAM", "THEDEVELOPERIDHERE");
youTubeService.setUserCredentials(youTubeUsername, youTubePassword);
System.out.println("Authentication of YouTube Service succeeded");
}
}
Any help on this would be great! Also, before I call the uploadToYouTube() method, I print out that the video's being uploaded to YouTube and after the method call I print out that it finished. Can someone explain why those are printed out within moments of one another? I'm not starting a new thread for the uploadToYouTube() method, I'm guessing that in the insert() method on the youTubeService there's a new thread started for the upload. It's a little annoying though because I'm never quite sure at what point the video finishes uploading and if I stop the program before it's through then the video stops uploading.
Anyway! Thanks for reading all of this! I hope someone can help me out!
The solution was really simple! The problem was even though I'm not over the 500 character limit for total tags, but sometimes I was over the limit of 30 characters per tag! I just changed tag adding lines to the following code:
//Keywords
mg.setKeywords(new MediaKeywords());
int totalTagsLimit = 500; // characters
int singleTagLimit = 30; // characters
int totalTags = 0; //characters
for (String tag : tags) {
if ((totalTags + tag.length()) < totalTagsLimit && tag.length() < singleTagLimit) {
mg.getKeywords().addKeyword(tag);
totalTags += tag.length();
}
}

Categories

Resources