#30 WIP - cleanup

This commit is contained in:
Denny
2016-12-11 10:38:23 -05:00
parent b65ff17ede
commit 1c8362c1fc
5 changed files with 57 additions and 5 deletions

View File

@@ -92,6 +92,11 @@ public abstract class AudioBroadcaster implements IAudioPacketListener
SystemProperties.getInstance().getApplicationFolder(BroadcastModel.TEMPORARY_STREAM_DIRECTORY)); SystemProperties.getInstance().getApplicationFolder(BroadcastModel.TEMPORARY_STREAM_DIRECTORY));
} }
protected ThreadPoolManager getThreadPoolManager()
{
return mThreadPoolManager;
}
/** /**
* Broadcast binary audio data frames or sequences. * Broadcast binary audio data frames or sequences.
*/ */

View File

@@ -365,8 +365,18 @@ public class BroadcastModel extends AbstractTableModel implements Listener<Audio
DefaultAsyncHttpClientConfig config = DefaultAsyncHttpClientConfig config =
new DefaultAsyncHttpClientConfig.Builder() new DefaultAsyncHttpClientConfig.Builder()
.setReadTimeout(-1) .setReadTimeout(-1)
.setThreadPoolName("audio-broadcast-pool")
.setUserAgent(SystemProperties.getInstance().getApplicationName())
.build(); .build();
mLog.debug("Client Config - Request Timeout:" + config.getRequestTimeout());
mLog.debug("Client Config - Connection Ttl:" + config.getConnectionTtl());
mLog.debug("Client Config - Connect Timeout:" + config.getConnectTimeout());
mLog.debug("Client Config - IO Thread Count:" + config.getIoThreadsCount());
mLog.debug("Client Config - Pool Conn Idle Timeout:" + config.getPooledConnectionIdleTimeout());
mLog.debug("Client Config - Connection Pooling:" + config.getIoThreadsCount());
mDefaultAsyncHttpClient = new DefaultAsyncHttpClient(config); mDefaultAsyncHttpClient = new DefaultAsyncHttpClient(config);
} }

View File

@@ -38,7 +38,7 @@ public enum BroadcastState
/** /**
* Disconnected from the broadcastAudio server * Disconnected from the broadcastAudio server
*/ */
DISCONNECTED("Disconnected", true), DISCONNECTED("Disconnected", false),
/** /**
* Invalid password * Invalid password

View File

@@ -42,6 +42,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import properties.SystemProperties; import properties.SystemProperties;
import java.net.ConnectException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
@@ -248,6 +249,7 @@ public class IcecastHTTPAudioBroadcaster extends AudioBroadcaster implements Pub
if(canConnect() && System.currentTimeMillis() - mLastConnectionAttempt >= RECONNECT_INTERVAL_MILLISECONDS) if(canConnect() && System.currentTimeMillis() - mLastConnectionAttempt >= RECONNECT_INTERVAL_MILLISECONDS)
{ {
mLog.debug("Creating a connection to icecast server"); mLog.debug("Creating a connection to icecast server");
setBroadcastState(BroadcastState.CONNECTING);
mLastConnectionAttempt = System.currentTimeMillis(); mLastConnectionAttempt = System.currentTimeMillis();
Uri uri = new Uri(Uri.HTTP, null, getConfiguration().getHost(), getConfiguration().getPort(), Uri uri = new Uri(Uri.HTTP, null, getConfiguration().getHost(), getConfiguration().getPort(),
@@ -299,7 +301,8 @@ public class IcecastHTTPAudioBroadcaster extends AudioBroadcaster implements Pub
requestBuilder.addHeader(IcecastHeader.EXPECT.getValue(), HTTP_100_CONTINUE); requestBuilder.addHeader(IcecastHeader.EXPECT.getValue(), HTTP_100_CONTINUE);
ListenableFuture<Response> future = requestBuilder.execute(new AsyncHttpConnectionResponseHandler()); requestBuilder.setRequestTimeout(1000);
requestBuilder.execute(new AsyncHttpConnectionResponseHandler());
} }
else else
{ {
@@ -313,8 +316,19 @@ public class IcecastHTTPAudioBroadcaster extends AudioBroadcaster implements Pub
@Override @Override
public void onThrowable(Throwable throwable) public void onThrowable(Throwable throwable)
{ {
mLog.error("BROADCAST error", throwable); mLog.debug("Got a throwable!");
setBroadcastState(BroadcastState.BROADCAST_ERROR); if(throwable instanceof ConnectException)
{
if(throwable.getMessage().contains("Connection refused"))
{
setBroadcastState(BroadcastState.NO_SERVER);
}
}
else
{
mLog.error("Error connecting to remote server - " + throwable.getMessage());
setBroadcastState(BroadcastState.BROADCAST_ERROR);
}
mConnecting.compareAndSet(true, false); mConnecting.compareAndSet(true, false);
} }
@@ -393,13 +407,15 @@ public class IcecastHTTPAudioBroadcaster extends AudioBroadcaster implements Pub
@Override @Override
public State onHeadersReceived(HttpResponseHeaders httpResponseHeaders) throws Exception public State onHeadersReceived(HttpResponseHeaders httpResponseHeaders) throws Exception
{ {
mLog.debug("Got headers received");
return State.CONTINUE; return State.CONTINUE;
} }
@Override @Override
public Response onCompleted() throws Exception public Response onCompleted() throws Exception
{ {
mLog.debug("We're completed"); mLog.debug("Got on completed");
setBroadcastState(BroadcastState.DISCONNECTED);
return null; return null;
} }
} }

21
src/network.java Normal file
View File

@@ -0,0 +1,21 @@
/*******************************************************************************
* sdrtrunk
* Copyright (C) 2014-2016 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
******************************************************************************/
public class network
{
}