Skip to content

Commit

Permalink
Merge pull request #95 from buddycloud/develop
Browse files Browse the repository at this point in the history
merging changes from develop
  • Loading branch information
abmargb committed Jan 6, 2015
2 parents cae3124 + aeb1132 commit eeab851
Show file tree
Hide file tree
Showing 12 changed files with 232 additions and 74 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ RUN apt-get upgrade -y
RUN apt-get install -y --no-install-recommends maven

RUN git clone https://github.com/buddycloud/buddycloud-media-server.git
RUN cd buddycloud-media-server && git checkout develop
RUN cd buddycloud-media-server && git checkout master
RUN cd buddycloud-media-server && mvn package
ADD contrib/docker/start.sh /data/
RUN chmod +x start.sh
CMD ./start.sh
CMD ./start.sh
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,38 @@ property will be used (default is *org.postgresql.Driver*).
- **media.storage.root** (Required): root path where the media server will store the media files.
- **media.sizelimit** (Optional): the tolerated file content size which the media server will store (default is *104857600* - 100 MB).
- **media.todisk.threshold** (Optional): the tolerated file size in bytes (default is *1048576* - 1 MB) which beyond are directly stored on disk.

### Logging

The buddycloud media server relies on [logback](http://logback.qos.ch/manual/configuration.html) for writing logs out. In order to configure itself, Logback will:

1. try to find a file called logback.groovy in the classpath.

1. If no such file is found, it tries to find a file called logback-test.xml in the classpath.

1. If no such file is found, it checks for the file logback.xml in the classpath..

1. If neither file is found, logback configures itself automatically using the BasicConfigurator which will cause logging output to be directed to the console.

A logback.xml with two appenders (```STDOUT``` writing in the console and ```FILE``` writing on a file) and with the root logger using the ```FILE``` appender looks like this:

```xml
<configuration>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>/var/log/buddycloud-media-server/mediaserver.log</file>
<encoder>
<pattern>%-5relative %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%-5relative %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>

<root level="DEBUG">
<appender-ref ref="FILE" />
</root>
</configuration>
```
3 changes: 2 additions & 1 deletion contrib/init.d/buddycloud-media-server
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ RUNFROM=/usr/share/buddycloud-media-server
DAEMON=/usr/bin/java
JAR_FILE="$(ls $RUNFROM/buddycloud-media-server-jar-with-dependencies.jar)"
JAR_FILE="$(basename $JAR_FILE)"
DAEMON_ARGS=" -Xms1024m -Xmx1024m -XX:-OmitStackTraceInFastThrow -Djava.awt.headless=true \
DAEMON_ARGS=" -Dlogback.configurationFile=logback.xml -Xms1024m -Xmx1024m \
-XX:-OmitStackTraceInFastThrow -Djava.awt.headless=true \
-cp .:$JAR_FILE com.buddycloud.mediaserver.Main"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/buddycloud-media-server
Expand Down
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@
<artifactId>easymock</artifactId>
<version>3.2</version>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.0</version>
<scope>test</scope>
</dependency>
<!-- Java Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
Expand Down
5 changes: 1 addition & 4 deletions postgres/upgrade-2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ CREATE TABLE "configuration" ("key" TEXT NOT NULL,
"updated" TIMESTAMP);

INSERT INTO schema_version (version, "when", description)
VALUES (8, 'now', 'Added configuration table');
VALUES (2, NOW(), 'Added configuration table');

COMMIT;

INSERT INTO schema_version (version, "when", description)
VALUES (2, NOW(), 'Add configuration table');
81 changes: 48 additions & 33 deletions src/main/java/com/buddycloud/mediaserver/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
*/
package com.buddycloud.mediaserver;

import com.buddycloud.mediaserver.commons.MediaServerConfiguration;
import com.buddycloud.mediaserver.web.MediaServerApplication;
import com.buddycloud.mediaserver.xmpp.MediaServerComponent;
import com.buddycloud.mediaserver.xmpp.XMPPToolBox;
import org.jivesoftware.smack.*;
import java.util.Properties;

import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Packet;
Expand All @@ -33,12 +34,15 @@
import org.slf4j.LoggerFactory;
import org.xmpp.component.ComponentException;

import java.util.Properties;
import com.buddycloud.mediaserver.commons.MediaServerConfiguration;
import com.buddycloud.mediaserver.web.MediaServerApplication;
import com.buddycloud.mediaserver.xmpp.MediaServerComponent;
import com.buddycloud.mediaserver.xmpp.XMPPToolBox;

public class Main {
private static Logger LOGGER = LoggerFactory.getLogger(Main.class);

public static void main(String[] args) {
public static void main(String[] args) throws InterruptedException {
Properties configuration = MediaServerConfiguration.getInstance()
.getConfiguration();

Expand All @@ -49,14 +53,7 @@ public static void main(String[] args) {
System.exit(1);
}

try {
while (!startXMPPToolBox(configuration)) {
Thread.sleep(5000);
}
} catch (Exception e) {
LOGGER.error("Error while starting XMPP client / component", e);
}

startXMPPToolBox(configuration);
keepAlive();
}

Expand Down Expand Up @@ -117,26 +114,39 @@ private static void setXMPPReplyTimeout(Properties configuration) {
MediaServerConfiguration.XMPP_REPLY_TIMEOUT));
SmackConfiguration.setPacketReplyTimeout(xmppReplyTimeout);
}

private static boolean startXMPPToolBox(Properties configuration) {

private static void startXMPPToolBox(Properties configuration)
throws InterruptedException {
setXMPPReplyTimeout(configuration);

XMPPConnection connection = createAndStartConnection(configuration);
addTraceListeners(connection);
LOGGER.info("Buddycloud Media Server XMPP client connection started!");

MediaServerComponent component;
try {
component = createXMPPComponent(configuration);
} catch (ComponentException e) {
return false;
}

XMPPToolBox.getInstance().start(component, connection);

LOGGER.info("Buddycloud Media Server XMPP component started!");

return true;
XMPPConnection connection = null;

while (true) {
try {
connection = createAndStartConnection(configuration);
addTraceListeners(connection);
LOGGER.info("Buddycloud Media Server XMPP client connection started!");
break;
} catch (Exception e) {
LOGGER.error("Error while starting XMPP client", e);
}
Thread.sleep(30000);
}

MediaServerComponent component = null;

while (true) {
try {
component = createXMPPComponent(configuration);
LOGGER.info("Buddycloud Media Server XMPP component started!");
break;
} catch (Exception e) {
LOGGER.error("Error while starting XMPP component", e);
}
Thread.sleep(30000);
}

XMPPToolBox.getInstance().start(component, connection, configuration);
}

private static MediaServerComponent createXMPPComponent(
Expand Down Expand Up @@ -211,6 +221,11 @@ private static XMPPConnection createAndStartConnection(
configuration.getProperty(MediaServerConfiguration.XMPP_CONNECTION_PASSWORD));
} catch (org.jivesoftware.smack.XMPPException e) {
LOGGER.error("XMPP connection coudn't be started", e);
try {
connection.disconnect();
} catch (Exception e2) {
// Do nothing, best effort
}
throw new com.buddycloud.mediaserver.commons.exception.XMPPException(e.getMessage(), e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static BufferedImage createImagePreview(BufferedImage img,
public static BufferedImage cropMaximumSquare(BufferedImage img) throws IOException {
int smallerSide = img.getHeight() <= img.getWidth() ? img.getHeight() : img.getWidth();
final BufferedImage cropedImg =
Thumbnails.of(img).sourceRegion(Positions.CENTER, smallerSide/2, smallerSide/2).size(smallerSide, smallerSide).asBufferedImage();
Thumbnails.of(img).sourceRegion(Positions.CENTER, smallerSide, smallerSide).size(smallerSide, smallerSide).asBufferedImage();
return cropedImg;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.buddycloud.mediaserver.business.util;

import org.jivesoftware.smack.Connection;
import org.jivesoftware.smackx.pubsub.PubSubManager;

public class PubSubManagerFactory {

private Connection connection;

public PubSubManagerFactory(Connection connection) {
this.connection = connection;
}

public PubSubManager create(String domain) {
return new PubSubManager(connection, domain);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,14 @@ private void addField(Element xEl, String var, String type,
fieldEl.addAttribute("type", type);
fieldEl.addElement("value").setText(value);
}

@Override
public void postComponentShutdown() {
LOGGER.debug("Buddycloud Media XMPP component was disconnected.");
}

@Override
public void postComponentStart() {
LOGGER.debug("Buddycloud Media XMPP component is connected and ready to accept packets.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
*/
package com.buddycloud.mediaserver.xmpp;

import java.util.Properties;

import com.buddycloud.mediaserver.commons.exception.XMPPException;
import com.buddycloud.mediaserver.xmpp.pubsub.PubSubClient;

import org.jivesoftware.smack.XMPPConnection;

public class XMPPToolBox {
Expand All @@ -36,10 +39,10 @@ public static XMPPToolBox getInstance() {
}

public void start(MediaServerComponent component,
XMPPConnection connection) {
XMPPConnection connection, Properties configuration) {
if (!started) {
authClient = new AuthVerifier(component);
pubSubClient = new PubSubClient(connection);
pubSubClient = new PubSubClient(connection, configuration);

started = true;
}
Expand Down
Loading

0 comments on commit eeab851

Please sign in to comment.